CheckedListBox binding


I am having trouble with the checkedListbox.

I would like to bind list(of pages) where the pages class has 2 properties


-IsChecked (boolean)

I can do this using:

Me.CheckedListBox1.DataSource = Me.mLstPages
Me.CheckedListBox1.DisplayMember = “Name”
Me.CheckedListBox1.ValueMember = “IsChecked”


However, if I have the “IsChecked” property set to true, the checkboxes are not checked.

What am I doing wrong?






  • You must to post comments

The ValueMember is the name of the property in the data source that provides the value for the items.

The DisplayMember is the name of the property in the data source that provides the value used to dispay the items.

If you use “IsChecked” as the name of the ValueMember and your data source has a property IsChecked, it will simply bind the value to that property. It is not related to the checked state of an item. Items do not have a checked state since their type is entirely up to your application. That’s the standard implementation in WinForms.

There would have to be a third binding property, something like CheckStateMember. It can be an enhancement for when we add binding to the ListView and possibly the TreeView.

One way to do this would be override RefreshItems() and in there loop over the items:

for (int i = 0; i < this.Items.Count; i++)
this.SetItemChecked(i, ((dynamic)this.Items[i]).Checked);

It obviously depends on your binding source and your classes in the app.





  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.