I have a class with two properties and I want to bind it to a CheckedListBox item. WebsiteName property will be the DisplayValue and IsChecked should be the Checked state of
The CheckedListBox control doesn't really support a DataSource, which is why the designers hid it from Intellisense. You can use it, but the checkmark property of the listbox won't work with your class, even if you set the ValueMember property to your boolean property.
Unfortunately, it means you have to set the values yourself:
checkedlistbox.DataSource = list;
checkedlistbox.DisplayMember = "WebsiteName";
for (int i = 0; i < checkedListbox.Items.Count; ++i) {
checkedListbox.SetItemChecked(i, ((ACLASS)checkedListbox.Items[i]).IsChecked);
}
and you also have to track the changes yourself, too:
checkedListBox1.ItemCheck += (sender, e) => {
list[e.Index].IsChecked = (e.NewValue != CheckState.Unchecked);
};
checkedlistbox.ValueMember = "IsChecked";