我正在尝试将标签绑定(bind)到 CheckedListBox.CheckedItems.Count 我已经尝试了几种方法并收到消息:
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)
我知道代码是 VB,但如果您有 C# 版本 - 我可以而且很乐意转换它。
最佳答案
由于 CheckListBox
不支持多选,您可能指的是 CheckItems.Count
。您不能绑定(bind)到 CheckItems.Count
。要收到有关 CheckedItem.Count
更改的通知,您应该处理 ItemCheck
CheckedListBox
的事件:
C#
this.checkedListBox1.ItemCheck += (s, ea) =>
{
this.BeginInvoke(new Action(() =>
{
this.label1.Text = this.checkedListBox1.CheckedItems.Count.ToString();
}));
};
关于c# - 如何绑定(bind)到 CheckedListBox.SelectedItems.Count,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39773497/