Dev CheckedListBox Dynamically bind data

Source: Internet
Author: User

I've had a problem with the project recently. Binds the data with the CheckedListBox control. A little summary here.

In fact, there are two ways to bind data dynamically.

1. Through the data source

DataTable dt=new DataTable ();//Data source Checkedlistboxcontrol yourcontrol=new Checkedlistboxcontrol (); Yourcontrol.displaymember= "Chinese name displayed"; yourcontrol.valuemember= "binding corresponding value";//This is often used to bind the ID and the like To do after the treatment of YOURCONTROL.DATASOURCE=DT;

Of course, the assignment to DisplayMember and ValueMember is consistent with the corresponding column names in your data source.

2. Manually insert data into a single piece

When you manually insert data and want to implement the first thing that binds something like value, you need to do a bit of processing.

    public class TestClass    {        String strvalue;        String text;        Public String Text         {            get            {                return Text;            }            Set             {                text = value;            }        }        Public String Value        {            get            {                return strvalue;            }            Set            {                strvalue= value;}}   } Here TESTCALSS can also add some properties to make it easier to deal with things related to your project. TestClass t=new TestClass (); Checkedlistboxcontrol yourcontrol=new Checkedlistboxcontrol (); YourControl.Items.Add (T,t.text, Checkstate.unchecked,true)///You can add more than one by loop//By adding data through the above method. Here's how to traverse for (int i = 0; i < CKLB. Checkeditems.count; i++) {       TestClass t= (TestClass) yourcontrol.checkeditems[i];       T.text;       T.value;}
By type conversion, you can access the corresponding property.
If you have any questions, please do not forget to spray.

Dev CheckedListBox Dynamically bind data

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.