Could anyone explain why the difference of behavior
betweein Case1 and Case2 occurs?
Microsoft Visual C#.NET 55607-652-0000007-18218
Windows Forms Application
1. put a TabControl on a Form and make a few TabPages
2. put a ComboBox on the one of them
3. run this code and move to the TabPages where the ComboBox sits
4. select some item of the ComboBox and move to the other TabPage
5. get back to the TabPage where the ComboBox sits
6. (Case 1) this action resets the selection of the ComboBox
6. (Case 2) this action won't affect the selection of the ComboBox
Thanks,
iStaion / YNT
Code ----------------------------------------------------------
private void Form1_Load(object sender, System.EventArgs e)
{
// Case 1
ComboBox1.DataSource = new ArrayList();
((ArrayList)ComboBox1.DataSource).Add(new ListValueMember("Item0",0));
((ArrayList)ComboBox1.DataSource).Add(new ListValueMember("Item1",1));
((ArrayList)ComboBox1.DataSource).Add(new ListValueMember("Item2",2));
((ArrayList)ComboBox1.DataSource).Add(new ListValueMember("Item3",3));
ComboBox1.DisplayMember = "DisplayMember";
ComboBox1.ValueMember = "ValueMember";
// Case 2
/*
ArrayList ar = new ArrayList();
ar.Add(new ListValueMember("Item0",0));
ar.Add(new ListValueMember("Item1",1));
ar.Add(new ListValueMember("Item2",2));
ar.Add(new ListValueMember("Item3",3));
ComboBox1.DataSource = ar;
ComboBox1.DisplayMember = "DisplayMember";
ComboBox1.ValueMember = "ValueMember";
*/
}
private class ListValueMember
{
private int mValueMember;
private string mDisplayMember;
public ListValueMember(string DisplayMember, int ValueMember)
{
this.mValueMember = ValueMember;
this.mDisplayMember = DisplayMember;
}
public int ValueMember
{
get
{
return mValueMember;
}
}
public string DisplayMember
{
get
{
return mDisplayMember;
}
}
}