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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.