Original address: http://blog.csdn.net/lucky51222/article/details/41892429
1. Add check box: Listview1.checkboxes = true;
2. Select the ListView and get the selected number:
[CSharp]View PlainCopy
- Private void listview1_itemchecked (object sender, Itemcheckedeventargs e)
- {
- e.item.selected = e.item.checked;
- m = ListView1.CheckedItems.Count;
- Label1. Text = "Current number of selected:" + m.tostring ();
- }
Note: Click the checkbox or double-click the ListView to select a row, but unlike the ComboBox control, get the selected number to use:m = listView1.CheckedItems.Count; And not listView1.SelectedItems.Count;!!!!!!!!!
3. Get multiple values selected in the check box in the ListView
[CSharp]View PlainCopy
- int k = 0;
- int m = ListView1.CheckedItems.Count;
- String[] A = new string[m];
- queue<string> Q = new queue<string> ();
- for (int i = 0; i < m; i++)
- if (Listview1.checkeditems[i]. Checked)
- Q.enqueue (Listview1.checkeditems[i]. SUBITEMS[1]. Text);
- while (Q.count > 0)
- {
- A[k] = Q.dequeue ();
- k++;
- }
C#listview Control Add checkbox check box and get the selected number, check if checkbox is checked