Catching Unselecting All in ListView — SelectedIndexChanged Firing Twice

前端 未结 5 1052
面向向阳花
面向向阳花 2021-01-19 21:37

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

5条回答
  •  没有蜡笔的小新
    2021-01-19 21:55

    You can do something like this:

             private bool isInitialized = false;
             private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
                 if (isInitialized) {
                     ListView.SelectedListViewItemCollection collection = this.listView1.SelectedItems;
    
                     if (collection.Count == 0) {
                         this.label2.Text = "Unselected all!";
                     }
                     foreach (ListViewItem item in collection) {
                         getSideInformation(item.Text);
                     }
                 }
                 isInitialized = true;
            }
    

    That will insure that first firing is ignored.

提交回复
热议问题