Select index from listview

后端 未结 4 743
不思量自难忘°
不思量自难忘° 2021-01-15 03:01

I\'m having some problem to get the index of the selected row in a listview. I wonder why this code isn\'t working? I get a red line below the SelectedIndex

         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-15 03:29

    private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Acquire SelectedItems reference.
            var selectedItems = listView1.SelectedItems;
            if (selectedItems.Count > 0)
            {
            // Display text of first item selected.
            this.Text = selectedItems[0].Text;
            }
            else
            {
            // Display default string.
            this.Text = "Empty";
            }
        }
    

提交回复
热议问题