繁体   English   中英

如何绑定到 CheckedListBox.SelectedItems.Count

[英]How To Bind to CheckedListBox.SelectedItems.Count

我正在尝试将标签绑定到 CheckedListBox.CheckedItems.Count 我已经尝试了几种方法并收到消息:

无法绑定到 DataSource 上的属性或列 Count。 参数名称: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 您不能绑定到CheckItems.Count 要获得有关CheckedItem.Count更改的通知,您应该处理CheckedListBox ItemCheck事件:

C#

this.checkedListBox1.ItemCheck += (s, ea) =>
{
    this.BeginInvoke(new Action(() =>
    {
        this.label1.Text = this.checkedListBox1.CheckedItems.Count.ToString();
    }));
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM