-->

Saturday, June 8, 2013

How to bind CheckedListBox using database In windows forms

How to bind CheckedListBox using database In windows forms

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.



To add a list of items at run time there is a function i.e. AddRange() that need a parameter of type array. We can add individual items using simple Add() method.
bind CheckedListBox using database
When we run our project it will look like:

bind CheckedListBox using database image

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:
data context class
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.
binding listing item
When we will run our project it will show a message box having items that are checked in our CheckedListBox.
binding output

Download Source code

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved