CheckedListBox binding

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
0
0

I am having trouble with the checkedListbox.

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

-Name

-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?

Thanks

 

 

 

 

  • You must to post comments
0
0

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.

HTH

Best,

Luca

 

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 5, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json