J
Joe
Hi
I am adding a class to a ComboBox - and all is fine except that I fill the
combobox on the
Form_Load Method and it causes the method
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
To fire twice
Once when I comboBox2.DataSource = allMonths;
And again when I execute comboBox2.DisplayMember = "Name";
Anybody seen this - I want to detect when a selection has changed in the
combobox - should I use another method??
{
Form1_Load
{
ArrayList allItems = new ArrayList();
allItems.Add(new TypePair("Item1", 1));
allItems.Add(new TypePair("Item2", 2));
allItems.Add(new TypePair("Item3", 3));
allItems.Add(new TypePair("Item4", 4));
comboBox2.DataSource = allItems;
comboBox2.DisplayMember = "Name";
comboBox2.ValueMember = "ID";
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox2.SelectedValue.ToString());
}
}
class TypePair
{
string m_Name;
int m_ID;
public string Name
{
get{ return (m_Name);}
set { m_Name = value; }
}
public int ID
{
get { return (m_ID); }
set { m_ID = value; }
}
public TypePair(string name, int nID)
{
this.m_Name = name;
this.m_ID = nID;
}
public override string ToString()
{
return m_Name;
}
}
I am adding a class to a ComboBox - and all is fine except that I fill the
combobox on the
Form_Load Method and it causes the method
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
To fire twice
Once when I comboBox2.DataSource = allMonths;
And again when I execute comboBox2.DisplayMember = "Name";
Anybody seen this - I want to detect when a selection has changed in the
combobox - should I use another method??
{
Form1_Load
{
ArrayList allItems = new ArrayList();
allItems.Add(new TypePair("Item1", 1));
allItems.Add(new TypePair("Item2", 2));
allItems.Add(new TypePair("Item3", 3));
allItems.Add(new TypePair("Item4", 4));
comboBox2.DataSource = allItems;
comboBox2.DisplayMember = "Name";
comboBox2.ValueMember = "ID";
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox2.SelectedValue.ToString());
}
}
class TypePair
{
string m_Name;
int m_ID;
public string Name
{
get{ return (m_Name);}
set { m_Name = value; }
}
public int ID
{
get { return (m_ID); }
set { m_ID = value; }
}
public TypePair(string name, int nID)
{
this.m_Name = name;
this.m_ID = nID;
}
public override string ToString()
{
return m_Name;
}
}