I have implemented a combo box to display an Info property
of myClass as below:
In the form:
private void comboBox1_LostF ocus(object sender,
System.EventArg s e)
{
Debug.WriteLine (comboBox1.Text );
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
comboBox1.Items .Add(new myClass("1","aa a"));
comboBox1.Items .Add(new myClass("2","bb b"));
comboBox1.Items .Add(new myClass("3","cc c"));
comboBox1.Items .Add(new myClass("4","dd d"));
comboBox1.Displ ayMember ="Info";
comboBox1.Selec tedIndex = 0;
this.comboBox1. LostFocus+=new EventHandler
(comboBox1_Lost Focus);
}
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
of myClass as below:
In the form:
private void comboBox1_LostF ocus(object sender,
System.EventArg s e)
{
Debug.WriteLine (comboBox1.Text );
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
comboBox1.Items .Add(new myClass("1","aa a"));
comboBox1.Items .Add(new myClass("2","bb b"));
comboBox1.Items .Add(new myClass("3","cc c"));
comboBox1.Items .Add(new myClass("4","dd d"));
comboBox1.Displ ayMember ="Info";
comboBox1.Selec tedIndex = 0;
this.comboBox1. LostFocus+=new EventHandler
(comboBox1_Lost Focus);
}
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
Comment