簡體   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