【问题标题】:Weird behaviour of CheckedListBoxCheckedListBox 的奇怪行为
【发布时间】:2016-05-19 08:47:42
【问题描述】:

我有 2 个 CheckedListBox。一个是Databound(name clbAnnually) 而另一个(clbMonthly) 不是。对于未绑定的checklist 框(clbMonthly),我可以使用下面提到的行获取任何项目的文本:

    private void clbMonthly_ItemCheck(object sender, ItemCheckEventArgs e)
    {
      string itemText = clbMonthly.Items[e.Index].ToString();
    }

另一方面,如果是数据绑定的checklistbox(clbAnnually),我无法使用相同的代码获取项目的文本。为什么会这样??

    private void clbAnnually_ItemCheck(object sender, ItemCheckEventArgs e)
    {
     string itemText1 = clbAnnually.Items[e.Index].ToString();
    }

【问题讨论】:

  • 尝试时会发生什么?错误?结果无效?
  • 它在变量中显示“System.Data.DataRowView”

标签: c# winforms checkedlistbox


【解决方案1】:

仅仅因为您在某些情况下意外使用的内容并不意味着它是正确的。

适用于所有场景的正确方法是使用专门提供的方法GetItemText

string itemText = clbMonthly.GetItemText(clbMonthly.Items[e.Index]);

string itemText1 = clbAnnually.GetItemText(clbAnnually.Items[e.Index]);

【讨论】:

  • 感谢@Ivan 的解决方案。
猜你喜欢
  • 1970-01-01
  • 2012-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-08
  • 2015-07-20
  • 2010-10-03
  • 2021-07-12
相关资源
最近更新 更多