【问题标题】:How to set an icon for each object in TreeListView如何为 TreeListView 中的每个对象设置一个图标
【发布时间】:2014-08-10 10:08:03
【问题描述】:

我有一些图标应该显示在 RowObject 名称旁边的第一列中。 不同的图片与不同类型的对象相关。 这部分代码使用我需要的对象创建列。

    this.descriptionTView = new BrightIdeasSoftware.TreeListView();
    this.descriptionTView.CanExpandGetter = x =>
    {
    if ( ( x as ITreeViewItem ).Items != null )
       {
       return ( x as ITreeViewItem ).Items.Length > 0;
       }
    else
       {
       return false;
       }
    };                

    this.descriptionTView.ChildrenGetter = x => ( x as ITreeViewItem ).Items;

    var column1 = new BrightIdeasSoftware.OLVColumn( "", "Part0" );
    column1.AspectGetter = x => ( x as ITreeViewItem ).Part0;
    column1.IsEditable = true;

    var column2 = new BrightIdeasSoftware.OLVColumn( "", "Part1" );
    column2.AspectGetter = x => ( x as ITreeViewItem ).Part1;
    column1.IsEditable = true;
    column2.IsEditable = true;

    this.descriptionTView.Columns.Add( column1 );
    this.descriptionTView.Columns.Add( column2 );
    private List<ITreeViewItem> itemsList;
    descriptionTView.Roots = itemsList;

【问题讨论】:

  • 我相信this answer 就是您要找的。​​span>
  • 请您添加更多详细信息并发布您的代码的 sn-p 吗?在没有信息的情况下无法为您提供帮助。
  • 在 ObjectListView 中我们不使用 TreeNode 或 Node 我们添加不同的对象。

标签: c# objectlistview treelistview


【解决方案1】:

您必须创建并分配一个 ImageList,其中包含您要使用的图像,例如

descriptionTView.SmallImageList = imageList1;

然后您可以为所需的列实现 ImageGetter

column1.ImageGetter = delegate(object rowObject) {
    // decide depending on the rowObject which image to return
    return 0;
};

您还可以返回列表中图像的名称,而不是索引。

你可能需要设置

descriptionTView.OwnerDraw = true;

另一种方法是使用ImageAspectName直接从行对象获取图像

column1.ImageAspectName = "MyImage"; // Assuming your object has a property `public BitMap MyImage;`

【讨论】:

  • 谢谢。你真的帮助了我。
【解决方案2】:

你需要在你的TreeView中添加一个ImageList,然后你可以设置一个带有ImageKey属性的节点。

【讨论】:

  • 我不使用节点。我的对象不包含 ImageKey 属性。
猜你喜欢
  • 2012-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-08
  • 2019-02-22
  • 1970-01-01
相关资源
最近更新 更多