Linkage between checkedlistbox and checkedlistbox

Source: Internet
Author: User

Including saving and Loading

 

// Find the business type
Datatable dtyewu = sb. selectsyscode (0, true );

If (dtyewu. Rows. Count> 0)
{

Flagcbb = false;
Clb_yewu.datasource = dtyewu;
Clb_yewu.displaymember = "name ";
Clb_yewu.valuemember = "ID ";
Datarowview DR = clb_yewu.items [0] As datarowview;
Dtyewuleixingbind (Dr ["ID"]. tostring (), true );

Flagcbb = true;

}

Biz = RC. bizid. Split (';');
Pit = RC. PID. Split (';');
Selectcbb ();
Loadbing ();

Private void selectcbb ()
{
Int m = 0;
For (Int J = 0; j <clb_yewu.items.count; j ++)
{
Datarowview DR = clb_yewu.items [J] As datarowview;

For (INT I = 0; I <biz. length; I ++)
{
If (Dr ["ID"]. tostring () = biz [I])
{
Clb_yewu.setitemchecked (J, true );
Break;
}
}


}
}

/// <Summary>
/// All platform information
/// </Summary>
Private void selectpingtai ()
{
String m;
String [] PT;
Datatable dtapt = sb. selectallpingtai ();

Dtallpt. Columns. Add ("ID", typeof (int32 ));
Dtallpt. Columns. Add ("cd", typeof (string ));
Dtallpt. Columns. Add ("name", typeof (string ));
For (INT I = 0; I <dtapt. Rows. Count; I ++)
{

M = dtapt. Rows [I] [0]. tostring ();
PT = M. Split (';');
Foreach (string ptf in Pt)
{
Datarow DR = dtallpt. newrow ();
Dr ["ID"] = dtapt. Rows [I] [1]. tostring ();
Dr ["cd"] = PTF;
Dr ["name"] = dtapt. Rows [I] [2]. tostring ();
Dtallpt. Rows. Add (DR );
}
}
}

  
Private void evaluate (Object sender, eventargs e) {If (flagcbb) {string CDD = ""; int M = clb_yewu.selectedindex; If (convert (clb_yewu.items [m])> = 0) dtyewuleixingbind (random (), true); If (random (clb_yewu.items [m]) <= 0) {dtyewuleixingbind (random (), false) ;}} private void CLB _ Selectedindexchanged (Object sender, eventargs e) {int M = (checkedlistbox) sender ). selectedindex; If (checkedlistbox) sender ). checkeditems. indexof (checkedlistbox) sender ). items [m])> = 0) {for (Int J = 0; j <clb_yewu.items.count; j ++) {datarowview DR = clb_yewu.items [J] As datarowview; if (Dr ["ID"]. tostring () = (checkedlistbox) sender ). name) {clb_yewu.setitemchecked (J, true); break ;}}}} /// <Summary> /// Filtering Platform /// </Summary> /// <Param name = "ID"> </param> /// <returns> </returns> private datatable selectdypt (string ID) {datarow [] drarr = dtallpt. select ("Cd = '" + ID + "'"); datatable dtnew = dtallpt. clone (); For (INT I = 0; I <drarr. length; I ++) {dtnew. importrow (drarr [I]);} return dtnew ;} /// <summary> /// bind the platform /// </Summary> /// <Param name = "ID"> </param> private void dtyewulei Xingbind (string ID, bool select) // Xu {// datatable dtpingtai = sb. selectpingtai (CDD); datatable dtpingtai = selectdypt (ID); bool flag = false; foreach (control con in panel2.controls) {If (con. name = ID) {con. visible = true; flag = true; If (! Select) {for (Int J = 0; j <(checkedlistbox) con ). items. count; j ++) (checkedlistbox) con ). setitemchecked (J, false) ;}} else {con. visible = false ;}} if (! Flag) {checkedlistbox clb_yewu = new checkedlistbox (); clb_yewu.name = ID; clb_yewu.visible = true; If (dtpingtai. rows. count> 0) {clb_yewu.datasource = dtpingtai; clb_yewu.displaymember = "name"; identifier = "ID"; identifier + = new eventhandler (clb_selectedindexchanged);} size Ss = new size (200,150 ); clb_yewu.size = SS; clb_yewu.checkonclick = true; panel2.control S. add (clb_yewu) ;}# region modify the personal information platform load /// <summary> // platform data load /// </Summary> private void loadbing () {If (UID> 0) {for (INT z = 0; Z <biz. length; Z ++) {datatable dtpingtai = selectdypt (BIZ [Z]); checkedlistbox clb_yewu = new checkedlistbox (); clb_yewu.name = biz [Z]; clb_yewu.visible = true; if (dtpingtai. rows. count> 0) {clb_yewu.datasource = dtpingtai; clb_yewu.displaymember = "name"; CLB _ Yewu. valuemember = "ID";} size Ss = new size (200,150); clb_yewu.size = SS; panel2.controls. add (clb_yewu) ;}ptbinding () ;}/// <summary >/// select the corresponding database item /// </Summary> private void ptbinding () {int I = 0; foreach (control C in panel2.controls) {I = 0; For (Int J = 0; j <(checkedlistbox) c ). items. count; j ++) {datarowview DR = (checkedlistbox) c ). items [J] As datarowview; If (pit! = NULL) foreach (string PT in pit) {string [] P = pt. split ('-'); If (Dr ["cd"]. tostring () = P [0]) if (Dr ["ID"]. tostring () = P [1]) {(checkedlistbox) c ). setitemchecked (I, true); break ;}} I ++ ;}}}

  

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.