Hi, I've a winform and I'm trying to bind some elements at page load method. After that
listBox1_SelectedIndexChanged event fires automatically. Why it is happening?
Thanks in advance, Nagu
Hi, I've a winform and I'm trying to bind some elements at page load method. After that
listBox1_SelectedIndexChanged event fires automatically. Why it is happening?
Thanks in advance, Nagu
I assume that this is because your list box begins life with no items in it (so its SelectedIndex property is -1). As soon as it's populated, its SelectedIndex property changes to 0 (to select the first item in the now populated list box) and then SelectedIndexChanged event is now fired.
disable the event prior to binding:
listBox1.SelectedIndexChanged -= listBox1_SelectedIndexChanged;
re-enable after binding:
listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;