[SOLVED] CheckedListBox databainding and ValueMember

Answered Closed
0
0

Hi,

Question about CheckedListBox and binding to the check box value.

I have set DisplayMember propert to “Name”. And that seems to work.

And then ValueMember to “GoodGuy”. GoodGuy is a bool. But that does not work. Suggestions?

See attached picture.

Best regards,

Wilfred

  • You must to post comments
Best Answer
0
0

See attached sample with the CheckStateMember bound property (read/write).

  • You must to post comments
Great Answer
0
0

The purpose of ValueMember is to assign a value to each item in the list. When the user selects a list item, checkedListBox.ValueMember determines what checkedListBox.SelectedValue is. For example, if the DataSource objects have a property called ID, then SelectedValue can be used to get the ID of the currently selected value when checkedListBox.ValueMember = “ID”.

You can set the checkbox values to match bools in the DataSource using a for-loop and checkedListBox.SetItemChecked(int index, bool isChecked). The indices in the CheckedListBox match the ones in the DataSource.

i.e. :

for (int i = 0; i < dataList.Count; i++)
{
checkedListBox1.SetItemChecked(i, dataList[i].someBooleanValue);
}

Hope this helps,

Nick

  • You must to post comments
0
0

Hi Nick,

Thank you for the explanation of the ValueMember.

It would be nice if the control also had a databinding property called “CheckedMember” for binding to a property in the datasource.

Best regards,

Wilfred

  • You must to post comments
Showing 3 results