Alexs, the first and second arraylist have no connection with each other.
Arnold, you are correct. I made a mistake writing this text, it is like you
said.
Can anyone tell me why I can't clear the selection before it is posted?
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 ListBx1_SelectedValueChanged(object sender, System.EventArgs e)
{
ArrayList AL2= GetAL2Data(ListBx1.SelectedValue.ToString());
ListBx2.DisplayMember = "Long_Desc";
ListBx2.ValueMember = "NDB_No";
ListBx2.DataSource = AL2;
}
> >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
[quoted text clipped - 50 lines]
> that would load ListBx2 again, instead of getting ListBx2.SelectedValue and
> doing something with it.
> Alexs, the first and second arraylist have no connection with each other.
>
[quoted text clipped - 3 lines]
>
> Can anyone tell me why I can't clear the selection before it is posted?
Class Whatever
Public Boolean bBypass; // <-------- LOOOOOOK
> public Form1()
> {
>
> InitializeComponent();
You're going to have to set bBypass.
bBypass = true; // you have to do it here <------- LOOOOOK
> ArrayList A1 = GetA1Data();
> ListBx1.DataSource = A1;
[quoted text clipped - 4 lines]
> ListBx1.ClearSelected();
> ListBx1.SelectedIndex = -1;
bBypass = false; // You have to do it here. <---------LOOOOOOK
> }
>
> private void ListBx1_SelectedValueChanged(object sender, System.EventArgs
> e)
> {
if (bBypass != true) // <----- LOOOOOK
{
ArrayList AL2= GetAL2Data(ListBx1.SelectedValue.ToString());
ListBx2.DisplayMember = "Long_Desc";
ListBx2.ValueMember = "NDB_No";
ListBx2.DataSource = AL2;
}
> }
On the Form load you have to bypass the code in SelectedValueChanged,
because of you binding the Arraylist to the control and every entry from the
Arraylist is making the SelectedValueChange event firer, even
ClearSelected() and SelectedIndex = -1 is making the event firer.
I think if you make the changes, then everything will be ok and all entries
in the box will be non-selected.
You're going to have to do the same thing when you load Listbx2 of bypassing
the code in its SelectedValueChanged event, otherwise, you got the same
problem of code executing during the load of the listbox when it should not
be happening.
Jerry J - 10 Jun 2007 15:10 GMT
Mr. Arnold,
Your solution works. Thank you for that!
I wouldn't have expected that every entry from the Arraylist would make the
SelectedValueChange event fire. I would have expected it to fire one time
after the load?

Signature
Jerry J
> > Alexs, the first and second arraylist have no connection with each other.
> >
[quoted text clipped - 55 lines]
> problem of code executing during the load of the listbox when it should not
> be happening.
Mr. Arnold - 10 Jun 2007 17:21 GMT
> Mr. Arnold,
>
[quoted text clipped - 4 lines]
> SelectedValueChange event fire. I would have expected it to fire one time
> after the load?
I did a simple test with 3 entries in an arraylist and it fired all 3 times,
even on the Clear and Index = -1.
You have to set a condition on a form load to bypass events for a control if
code is in those events and they firer, when you're trying to load/set a
control with data.