=========這是Winform==================
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; }