Checkedlistboxcontrol to implement check boxes for radio and multi-select functions

Source: Internet
Author: User

Due to work needs, need to implement check box of radio and multi-select function, find a lot of information is not very full, after two days of digging and digging, finally finished O (∩_∩) o haha ~

With the Checkedlistboxcontrol control in the dev control, of course, the check box combo control in VS should be implemented as follows, and you can try it (⊙o⊙).

Code come O (∩_∩) o haha ~

1   //first trigger the SelectedIndexChanged event before triggering the ItemCheck event2        3         //stores the value of the selected check box4         stringstrgxy=string. Empty; 5         Private voidChkgxygrade_selectedindexchanged (Objectsender, EventArgs e)6         {7 8             //set all the selection boxes to the unchecked state first9              for(inti =0; i < ChkGXYGrade.Items.Count; i++)Ten             { One chkgxygrade.setitemcheckstate (i, checkstate.unchecked); A             } -         } -  the         Private voidChkgxygrade_itemcheck (Objectsender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) -         { -             //If the check box is selected with a number greater than 0, the index of the selected check box and E. Index (Gets the indexed of the currently selected clicked check box), select the check box if it is equal, or leave it unchecked -             if(ChkGXYGrade.CheckedItems.Count >0) +             { -                  for(inti =0; i < ChkGXYGrade.Items.Count; i++) +                 { A                     if(I! =E.index) at                     { - chkgxygrade.setitemcheckstate (i, checkstate.unchecked); -                     } -                 } -             } -             Else in             { -                to                 //If the check box has the selected data less than 0, the status of all check boxes is left unchecked +                  for(inti =0; i < ChkGXYGrade.Items.Count; i++) -                 { the  * chkgxygrade.setitemcheckstate (i, checkstate.unchecked); $Strgxy =string. Empty;Panax Notoginseng                 } -  the             } +  A              the             //loop check box to get the value of the selected check box according to the selected state +              for(inti =0; i < ChkGXYGrade.Items.Count; i++) -             { $                 if(Chkgxygrade.items[i]. CheckState = =checkstate.checked) $                 { -Strgxy =Chkgxygrade.getitemtext (i). ToString (); -                 } the             } -}
level can only select one event

1   //record check box selected status2 CheckState CSGXB;3 4         //store check box selected value (multi-select with '/' distinction)5         stringSTRGXB =string. Empty;6 7         //trigger the SelectedIndexChanged event before triggering the ItemCheck event8         Private voidChbgxblb_selectedindexchanged (Objectsender, EventArgs e)9         {Ten             Switch(CSGXB) One             { A                  Casecheckstate.checked: -  -STRGXB =string. Empty; the                      for(inti =0; i < ChbGXBlb.Items.Count; i++) -                     { -                         //gets the value of the selected check box -                         if(chbgxblb.getitemchecked (i)) +                         { -                             if(STRGXB = =string. Empty) +                             { ASTRGXB =Chbgxblb.getitemtext (i); at                             } -                             Else -                             { -STRGXB + ="/"+Chbgxblb.getitemtext (i); -                             } -                         } in                     } -                      Break; to                  Casecheckstate.unchecked: +STRGXB =string. Empty; -                      for(inti =0; i < ChbGXBlb.Items.Count; i++) the                     { *                         if(chbgxblb.getitemchecked (i)) $                         {Panax Notoginseng                             if(STRGXB = =string. Empty) -                             { theSTRGXB =Chbgxblb.getitemtext (i); +                             } A                             Else the                             { +STRGXB = Strgxb +"/"+Chbgxblb.getitemtext (i); -                             } $                         } $                     } -                      Break; -  the             } - Wuyi         } the  -  Wu   Private voidChbgxblb_itemcheck (Objectsender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) -         { About             //E.state, gets the status of whether the current check box is checked or unchecked (Checked or unchecked) $CSGXB =e.state; -Chbgxblb_selectedindexchanged (NULL,NULL); -}
Multi-select: To change the value of a selection

Checkedlistboxcontrol to implement check boxes for radio and multi-select functions

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.