Listview ItemSelectionChanged fires twice?

后端 未结 4 1091
天涯浪人
天涯浪人 2020-12-16 19:56

I have a Winforms App in C# with a ListView control. This ListView shows a list of TO-DO items and I am using the \'ItemSelectionChanged\' event to handle updates.

<
4条回答
  •  粉色の甜心
    2020-12-16 20:18

    Yes just remove the EventHandler at the start of the refresh and add it again after it has finished refreshing

    i.e

    // Remove handler
    listView1.ItemSelectionChanged -= new ListViewItemSelectionChangedEventHandler(listView1_ItemSelectionChanged);
    
    // Do refresh
    
    // Add again
    listView1.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(listView1_ItemSelectionChanged);
    

提交回复
热议问题