標籤:mod oid strong cte lis dev bar 選中 art
原地址:http://blog.csdn.net/lucky51222/article/details/41892429
1、添加複選框:listView1.CheckBoxes = true;
2、選中listview並擷取選中的數目:
[csharp] view plain copy
- private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
- {
- e.Item.Selected = e.Item.Checked;
- m = listView1.CheckedItems.Count;
- label1.Text = "當前選中數:" + m.ToString();
- }
說明:點擊複選框或者雙擊listview均可選中某一行,但是跟comboBox控制項不一樣的是,擷取選中數目要用:m = listView1.CheckedItems.Count;而不是listView1.SelectedItems.Count; !!!!!!!!!
3、擷取listview中複選框中選定的多個值
[csharp] view plain copy
- 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控制項添加Checkbox複選框並擷取選中的數目,檢查checkbox是否勾選