Data bound CheckedListBox

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello everyone!
I need to bind a CheckedListBox to a datasource such as an Access 2007 table.
The functionality I am looking for is as follows:
I have 2 ComboBoxes on a form bound to 2 separate tables in Access 2007. The first ComboBox called DistrictComboBox populates with names of Districts from the District table in the database. The second ComboBox "filters" Blocks (sub-districts) based on the
selection made in the District ComboBox. This part works fine as I make use of the BindingSources. Simply a matter of dragging and dropping appropriate tables from the DataSources in Visual Basic 2008 Express Edition onto the respective District and Block
ComboBoxes which automatically setup the bindings and filters the Blocks for the selected District.
The problem I am having is when I want to filter "Villages" inside those Blocks (Sub-Districts). I want to use a CheckedListBox which would populate with villages belonging to the particular chosen Block from the Block ComboBox.
<span style="font-family:Segoe UI,sans-serif; font-size:10pt; line-height:normal A CheckedListBox and a bunch of CheckBoxes are all bound to the same DataTable, then moving between items in the ListBox would move the binding.Position and the CheckBoxes
would correspond to the Village selected in the ListBox. Then all that would need to be done in the ListBox SelectedIndexChanged event is see whether the item is checked and disable/enable the CheckBoxes appropriately. This part isnt as easy as it sounds,
because there doesnt appear to be a Checked property on the ListBox, only a collection of CheckedItems. But, looping through the collection and checking each item by using the CheckedListBox.Items.IndexOf (item) to see if it equals the SelectedIndex.
When a user Checks a village in the CheckedListBox, the checked village should be updated in the Access 2007 database.<br/>

How should I accomplish this ??
Appreciate all help.
Best Regards,

View the full article
 
Back
Top