CheckedListBox
displays a list of items with a checkbox on the left side of each item. The user
can select one or more items by simply place a checkmark to one or more items. To
access those checked items we can use either CheckedListBox.CheckedItemCollection or CheckedListBox.CheckedIndexCollection in our code behind file.
When
we run our project it will look like:
CheckedListBox
provides two types of states i.e. Checked and Unchecked. There is one more
state i.e. Intermediate that must be set through code If we want to use this.
Now to bind this control using database we must have some entries in our
table and I have described this in my previous post. To bind CheckedListBox with our table we have to write following code in our Form’s
constructor:
After
bind this CheckedListBox it’s time to get checked items. To get checked items there
is a property i.e. CheckedItems type of CheckedItemCollection. So add a button
in our form and in the click event of that button we will get checked item one
by one and add it to a string variable and finally show this through a message
box.
When
we will run our project it will show a message box having items that are
checked in our CheckedListBox.
Download Source code