Skip to content

CheckedListBox binding #710

Closed
Closed

Description

@itg-assistant

Shawn Ramirez asked 2017-03-21 19:42:53 UTC

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

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-03-21 20:40:54 UTC

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions