1、设计窗体
一个ListView listView1
一个textBox txbSelected
2、listView1填充数据
private void Form1_Load(object sender, EventArgs e) { // listView1填充数据 ListViewItem list = listView1.Items.Add("1"); list.SubItems.Add("依依"); ListViewItem list1 = listView1.Items.Add("2"); list1.SubItems.Add("小二"); ListViewItem list3 = listView1.Items.Add("3"); list3.SubItems.Add("珊珊"); //显示选中listView1全行 listView1.FullRowSelect = true; }
3、选中全行触发事件
private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { string name = listView1.FocusedItem.SubItems[0].Text; name += " "; name += this.listView1.FocusedItem.SubItems[1].Text; txtSelected.Text = name; }
时间: 2024-12-09 14:12:22