See: ListBox select all items
I have a ListBox and I need to select all the items. The only problem is that I have event handlers in the ListBox.SelectIndexChanged event, which does some things that are CPU intensive. Selecting elements in a loop here causes the program to fire the SelectIndexChanged event at each iteration of the loop.
I included a loop in Suspend / ResumeLayout () as follows:
SuspendLayout(); for (int i = 0; i < listBox.Items.Count; i++) listBox.SetSelected(i, true); ResumeLayout();
but it still fires the event and still takes a long time to update the selection.
I could fix the problem with a simple boolean flag that I switch when the update starts, but if there is an easier way to resolve this issue, that would be great.
Thanks.
Ozzah source share