I have implemented a combo box to display an Info property
of myClass as below:
In the form:
private void comboBox1_LostFocus(object sender,
System.EventArgs e)
{
Debug.WriteLine(comboBox1.Text);
}
private void Form1_Load(object sender, System.EventArgs e)
{
comboBox1.Items.Add(new myClass("1","aaa"));
comboBox1.Items.Add(new myClass("2","bbb"));
comboBox1.Items.Add(new myClass("3","ccc"));
comboBox1.Items.Add(new myClass("4","ddd"));
comboBox1.DisplayMember ="Info";
comboBox1.SelectedIndex = 0;
this.comboBox1.LostFocus+=new EventHandler
(comboBox1_LostFocus);
}
public class myClass
{
private string _id;
private string _name;
public myClass(string id, string name)
{
_id = id;
_name = name;
}
public string Info
{
get {return _id + " and " + _name;}
}
}
the LostFocus event is fired when the combo box RECEIVE
FOCUS(this is weird), as well as lost focus (that is
expected).
Can somebody help explain why this happen, and how to get
around it?
Thanks
Ming