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
My Code is as Follows:
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)
I know the code is VB but if you have a C# version - I can and will be happy to convert it.
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();
}));
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.