Today, checkedlistbox is used to summarize common knowledge.
1. Add item: items. Add
Checkedlistbox1.items. Add ("June");
Checkedlistbox1.items. Add ("Jun");
2. Determine whether getitemchecked (INDEX) is selected for item I)
Checkedlistbox1.getitemchecked (I)
3. Set whether setitemchecked (index, bool) or setitemcheckstate (index, checkstate) is selected for item I)
Checkedlistbox1.setitemchecked (index,True);
Checkedlistbox1.setitemcheckstate (index, checkstate. Unchecked );
4. Set all options
For(IntI =0; I <listboxled. Items. Count; I ++)
{
Checkedlistbox1.setitemcheckstate (I, checkstate. Checked );
//Checkedlistbox1.setitemchecked (I, true );
}
5. Data Binding
Checkedlistbox should be extended by ListBox, but in use, you may find that -- it does not support the datasource attribute and cannot specify its data source as a datatable as ListBox.
As a matter of fact, checkedlistbox has the datasource attribute like ListBox, and both displaymember and valuememeber attributes are available, but intelliisense cannot intelligently perceive them.
Therefore, we canCodeBind the checkedlistbox.
Dataset DS = BLL. getallstudent ();
Checkedlistbox1.datasource = Ds. Table [0];
Checkedlistbox1.valuemember ="Student_id";
Checkedlistbox1.displaymember ="Student_name";
6. How to obtain the displaymember and valuemember of the checkedlistbox1 selected item
Method 1:
For(IntI =0; I <checkedlistbox1.checkeditems. Count; I ++)
{
Datarowview DV = (datarowview) checkedlistbox1.checkeditems [I]);
StringId = DV ["Student_id"]. Tostring ();
StringName = DV ["Student_name"]. Tostring ();
}
Method 2:
Get Text: it is easy to get text. You can get it on the checkedlistbox. Get the text of the selected item.
StringName = checkedlistbox1.getitemtext (checkedlistbox1.items [I]);
Get the value of value: here we use a technique to obtain the value by binding it to the dataset of checkedlistbox. (It is shown on the Internet that the index obtained in checkedlistbox is the same as the corresponding value in dataset..I want to explain the cause.)
StringName = Ds. Tables [0]. Rows [I] ["Student_name"]. Tostring ();//Here I is the index of the selected checkedlistbox item
If you think that checkedlistbox is commonly used, please add it.