namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//aggiungiamo una voce
listFields.Add(new Field("Comune", "Comune"));
}
BindingList<field> listFields = null;
private void Form1_Load(object sender, EventArgs e)
{
listFields = new BindingList<field>();
listFields.AllowNew = true;
listFields.AllowRemove = true;
listFields.AllowEdit = false;
listFields.RaiseListChangedEvents = true; //se serve sapere quando la lista cambia
listFields.Add(new Field("Provincie", "Provincie"));
listFields.Add(new Field("CM", "Comuni Montane"));
listFields.Add(new Field("CorsiAcqua", "Corsi Acqua"));
this.comboBox1.DisplayMember = "AliasName";
this.comboBox1.ValueMember = "Name";
this.comboBox1.DataSource = listFields;
}
void listFields_ListChanged(object sender, ListChangedEventArgs e)
{
MessageBox.Show(e.ListChangedType.ToString());
}
}
public class Field
{
public string Name
{
get {; }
set {; }
}
public string AliasName
{
get {; }
set {; }
}
public Field()
{
}
public Field(string name, string aliasName)
{
AliasName = aliasName;
Name = name;
}
}
}