【问题标题】:How to hide TreeListView error message about a row with missing column details?如何隐藏有关缺少列详细信息的行的 TreeListView 错误消息?
【发布时间】:2012-04-27 18:33:24
【问题描述】:

我有一个包含 2 列的 TreeListView 组件:“a”和“b”。

在我的列表中,有时我同时有“a”和“b”,但有时只有“a”。

如何消除“b”列中的以下消息(在不包含“b”的行中)?

"'b' 不是无参数的方法、属性或类型的字段..."

【问题讨论】:

  • 请显示您当前的代码以获得反馈/帮助。

标签: c# .net listview objectlistview treelistview


【解决方案1】:

我猜你说的是ObjectListView项目中的TreeListView

如果是这样,您必须在“b”列上安装AspectGetter。当没有 'b' 属性时,让该方面 getter 返回 null。

this.olvColumnB.AspectGetter = delegate(object x) {
    ModelWithPropertyB model = x as ModelWithPropertyB;
    return model == null ? null : model.B;
}

【讨论】:

  • 如果上例中 B 的返回值不可为空,那么您可以强制转换为对象以避免编译器抱怨找不到转换。返回模型 == 空? null : (object)model.B;
【解决方案2】:

当前版本的TreeListView(2.8.1,不知道什么时候添加的)的解决方法是设置:

BrightIdeasSoftware.TreeListView.IgnoreMissingAspects = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多