I am trying to bind a label to a CheckedListBox.CheckedItems.Count
I have tried a couple approaches to this and receive the message:
Cannot bind to the property or column Count on the DataSource.
Parameter name: dataMember
Dim BgCountBinding As Binding = New Binding("Text", BgCheckedListBox.CheckedItems, "Count")
' I have also tried this:
' Dim BgCountBinding As Binding = New Binding("Text", BgCheckedListBox, "CheckedItems.Count")
BgCountBinding.DataSourceUpdateMode = DataSourceUpdateMode.Never
BgCountBinding.ControlUpdateMode = ControlUpdateMode.OnPropertyChanged
BgCountBinding.NullValue = "0"
BgCountBinding.FormattingEnabled = True
BgCountBinding.FormatString = "#: {0}"
lblBGCount.DataBindings.Add(BgCountBinding)
Since the CheckListBox
doesn't support multi-selection, probably you mean CheckItems.Count
. You can not bind to CheckItems.Count
. To be notified about changing in CheckedItem.Count
you should handle ItemCheck
event of the CheckedListBox
:
C#
this.checkedListBox1.ItemCheck += (s, ea) =>
{
this.BeginInvoke(new Action(() =>
{
this.label1.Text = this.checkedListBox1.CheckedItems.Count.ToString();
}));
};