C # checklistbox usage

Source: Internet
Author: User

C # checklistbox usage

1. add items:

Checkedlistbox1.items. Add ("blue ");
Checkedlistbox1.items. Add ("red ");
Checkedlistbox1.items. Add ("yellow ");

2. Check whether 0th items are selected

If (checkedlistbox1.getitemchecked (0 ))

3. Set whether or not 0th items are selected

Checkedlistbox1.setitemchecked (0, true );

4. Set all options

Add a checkbox control named select_all

Private void select_all_checkedchanged (Object sender, eventargs E)
{
If (select_all.checked)
For (Int J = 0; j <checkedlistbox1.items. Count; j ++)
Checkedlistbox1.setitemchecked (J, true );
Else
For (Int J = 0; j <checkedlistbox1.items. Count; j ++)
Checkedlistbox1.setitemchecked (J, false );

}

5. Obtain all selected values:

Private void linklabel_yes_linkclicked (Object sender, linklabellinkclickedeventargs E)
{
Panel_friend.visible = false;
Button_friend.text = "friend panel ";
Sms_str = NULL;
For (Int J = 0; j <checkedlistbox1.items. Count; j ++)
// Sms_str = sms_str + checkedlistbox1.selecteditems [J]. tostring (). substring (); // note that [J] is not (j)
If (checkedlistbox1.getitemchecked (j ))
Sms_str = sms_str + checkedlistbox1.items [J]. tostring ();
Sms_content.text = sms_str;


}

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.