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