Catching Unselecting All in ListView — SelectedIndexChanged Firing Twice

前端 未结 5 1072
面向向阳花
面向向阳花 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:54

    You can register to ListView's ItemSelectionChangedEvent instead.

            this.listView1.ItemSelectionChanged += this.HandleOnListViewItemSelectionChanged;
    
            private void HandleOnListViewItemSelectionChanged(Object sender, ListViewItemSelectionChangedEventArgs e)
            {
                if (e.IsSelected)
                {
                    this.detailsLabel.Text = this.GetDetails(e.Item);
                }
                else
                {
                    this.detailsLabel.Text = String.Empty;
                }
            }
    

提交回复
热议问题