Listview ItemSelectionChanged fires twice?

后端 未结 4 1095
天涯浪人
天涯浪人 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:21

    Yes, it will fire twice. Once because the previously selected item became unselected, again for the newly selected item. You just have to make sure you see the selection event:

        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) {
            if (e.IsSelected) {
                // Update form
                //...
            }
        }
    

提交回复
热议问题