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 data to be grabbed). The behavior I was going for was to hide this text box on right when all items get unselected.
private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
// should only be 1 item selected, it's not a multi-select listview
ListView.SelectedListViewItemCollection collection = this.listView1.SelectedItems;
if (collection.Count == 0) {
this.label2.Visible = false;
}
foreach (ListViewItem item in collection) {
this.label2.Visible = true;
getSideInformation(item.Text);
}
}
I noticed a flicker of the box, when I am simply selecting another item. I did some digging by changing my code to:
private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
// should only be 1 item selected, it's not a multi-select listview
ListView.SelectedListViewItemCollection collection = this.listView1.SelectedItems;
if (collection.Count == 0) {
this.label2.Text = "Unselected all!"
}
foreach (ListViewItem item in collection) {
getSideInformation(item.Text);
}
}
Basically, I no longer hide the box, but just change the text if it's a selection change event with 0 items selected. What I found out is that this event actually fires TWICE for a simple select another item (once with 0 items, and a second time with the new items selected). So my box will always display "Unselected all!" while it's loading up any side information if I had previously selected an item and was changing to another item.
Is there any way to differentiate an actual event firing of all items unselected versus that initial firing of 0 items for the selecting another item case?