Pavel Shchegolevatykh
Pavel Shchegolevatykh

Reputation: 2634

CheckedListBox WinForms Binding

How can I bind my object collection to CheckedListBox items with IsChecked property?

Here is my objects:

public class Person
{
    public int Id {get;set;}
    public string Name {get;set;}
    public bool IsChecked {get;set;}
}

public class EditorModel
{
    public BindingList<Person> People {get;set;}
}

These objects both implement INotifyPropertyChanged also.

I can do binding like this:

checkedListBox.DataSource = editorViewModel.People;
checkedListBox.ValueMember = "Id";
checkedListBox.DisplayMember = "Name";

How can I bind the third property IsChecked? I tried to google it, but I haven't found any solution.

Upvotes: 3

Views: 3249

Answers (1)

Jeremy Thompson
Jeremy Thompson

Reputation: 65534

Problem

All the solutions in binding a datasource to a CheckedListBox aren't very elegant.

Solution

Use a DataGridView with a Checkbox column instead.

Upvotes: 5

Related Questions