G
Guest
I have two single selection list boxes on a windows form. Both forms get
bound to data in an ArrayList (IList). I want the data in the first list box
to be visible when the form loads. The data that appears in the second list
box is dependent on the slelection of the item in the first list box. So when
an item is selected in listbox 1, the ListBox2_SelectedValueChanged method is
called. This method will then load an ArrayList that is bound to the list box.
My problem is that the ListBox2_SelectedValueChanged gets called multiple
times when the form loads and causes it to crash. This has something to do
with an item being selected in listbox1. I've tried various methods to turn
off the ListBox1 selection, however, nothing seems to work. Should I go about
this some other way? It seems like this should be easy.
My code looks like this:
public Form1()
{
InitializeComponent();
ArrayList A1 = GetA1Data();
ListBx1.DataSource = A1;
ListBx1.DisplayMember = "Description";
ListBx1.ValueMember = "Code";
// niether of these will clear the selection
ListBx1.ClearSelected();
ListBx1.SelectedIndex = -1;
}
private void ListBx2_SelectedValueChanged(object sender, System.EventArgs e)
{
ArrayList AL2= GetAL2Data(ListBx1.SelectedValue.ToString());
ListBx2.DisplayMember = "Long_Desc";
ListBx2.ValueMember = "NDB_No";
ListBx2.DataSource = AL2;
}
bound to data in an ArrayList (IList). I want the data in the first list box
to be visible when the form loads. The data that appears in the second list
box is dependent on the slelection of the item in the first list box. So when
an item is selected in listbox 1, the ListBox2_SelectedValueChanged method is
called. This method will then load an ArrayList that is bound to the list box.
My problem is that the ListBox2_SelectedValueChanged gets called multiple
times when the form loads and causes it to crash. This has something to do
with an item being selected in listbox1. I've tried various methods to turn
off the ListBox1 selection, however, nothing seems to work. Should I go about
this some other way? It seems like this should be easy.
My code looks like this:
public Form1()
{
InitializeComponent();
ArrayList A1 = GetA1Data();
ListBx1.DataSource = A1;
ListBx1.DisplayMember = "Description";
ListBx1.ValueMember = "Code";
// niether of these will clear the selection
ListBx1.ClearSelected();
ListBx1.SelectedIndex = -1;
}
private void ListBx2_SelectedValueChanged(object sender, System.EventArgs e)
{
ArrayList AL2= GetAL2Data(ListBx1.SelectedValue.ToString());
ListBx2.DisplayMember = "Long_Desc";
ListBx2.ValueMember = "NDB_No";
ListBx2.DataSource = AL2;
}