I have a windows form with a listview control. I set the MultiSelect property to true and I added a selected_index changed event.
I get the event fired when I click the same index as the current selected index.
My expectation is that I will not get the event fired. The strange thing is that the event fired 1 second after I click the index.
I appreciate for any reply to explain why this is happening.
Edited:
Sample Code:
private void Form1_Load(object sender, EventArgs e)
{
listView1.View = View.Details;
listView1.MultiSelect = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Number");
listView1.Items.Add("1");
listView1.Items.Add("2");
listView1.Items.Add("3");
listView1.Items.Add("4");
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
MessageBox.Show("Selected Index Changed event fired: ");
}
}
Follow these steps to see the problem:
-
Try to select one item, for instance: select number 3
expected result: listview1_SelectedIndexChanged is fired
Result: It is fired.
-
Try to click the number 3 again.
expected result: listview1_SelectedIndexChanged is NOT fired
Result: It is fired with one second delay.
From the MSDN documention on ListView.SelectedIndexChangedEvent:
As for why the event waited so long to fire: I can only imagine the processor was tied up doing something else. Do you have more details regarding what you’re seeing, exactly (sample code would help)?