C#listview Control Add checkbox check box and get the selected number, check if checkbox is checked

Source: Internet
Author: User

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
    1. Private void listview1_itemchecked (object sender, Itemcheckedeventargs e)
    2. {
    3. e.item.selected = e.item.checked;
    4. m = ListView1.CheckedItems.Count;
    5. Label1.  Text = "Current number of selected:" + m.tostring ();
    6. }

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
  1. int k = 0;
  2. int m = ListView1.CheckedItems.Count;
  3. String[] A = new string[m];
  4. queue<string> Q = new queue<string> ();
  5. for (int i = 0; i < m; i++)
  6. if (Listview1.checkeditems[i]. Checked)
  7. Q.enqueue (Listview1.checkeditems[i]. SUBITEMS[1]. Text);
  8. while (Q.count > 0)
  9. {
  10. A[k] = Q.dequeue ();
  11. k++;
  12. }

C#listview Control Add checkbox check box and get the selected number, check if checkbox is checked

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.