C#winform version of CheckBox, Checklistbox control Traversal code

Source: Internet
Author: User

CheckBox, which is a common control in various development locales and Web pages.
Below, this article is to explain the c#winform version of the checkbox, control traversal, select all, anti-select instance code.
① Direct Reference
If a CheckBox control is present in a form, the method of direct reference is:
The control name. Property = Property Value
Example: Checkbox1.checked = true;
② Traversal Reference
There are two cases of traversing a reference, one for which the CheckBox control is not contained within any container, and the other is that the CheckBox control is contained within some containers.
A:checkbox traversal method that is not contained within any container

 foreach inch this. Controls)// Use this here.    Controls  {  if is as CheckBox;  ifnull)                true; // Select All                  }}}

A:checkbox the traversal method contained within the container (for example, contained within a groupbox)

 foreach  (Control mycheckbox in  Groupbox1.controls) //  use container name here GroupBox1   { if  (MyCheckBox Span style= "color: #0000ff;" >is   checkbox) {CheckBox ck  = MyCheckBox 
   
    as  
     CheckBox;  
    if  
     CK. Checked) {ck. Checked  =!ck. Checked; 
    // 
     inverse selection  
     
   

Another case is that the form does not use the CheckBox control control, but instead uses CheckBoxList, and if we want to implement traversal, refer to the following code:

   for (int i =0; i<checklistbox.items.count;i++) {MessageBox.Show (checklistbox.items[0) ].  ToString ()); }

C#winform version of CheckBox, Checklistbox control Traversal code

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.