Basically, I have a ListView of items. When one is selected, a text box comes into view on the right to display more details of that item (takes a little time for the item
The best solution I've found is to temporarily set an event handler to Application.Idle
and do your checking from there, like so:
bool handled;
private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
if (!handled)
{ handled = true;
Application.Idle += SelectionChangeDone; }
}
private void SelectionChangeDone(object sender, EventArgs e) {
Application.Idle -= SelectionChangeDone;
handled = false;
ListView.SelectedListViewItemCollection collection = this.listView1.SelectedItems;
if (collection.Count == 0)
this.label2.Text = "Unselected all!"
foreach (ListViewItem item in collection)
getSideInformation(item.Text);
}
It shouldn't matter whether you use ItemSelectionChanged
or SelectedIndexChanged
. Both will work fine in this case.
Big thanks goes to Grammarian for his answer to essentially the same question here: https://stackoverflow.com/a/26393234/2532220