3

我有一些图标应该显示在 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;
4

2 回答 2

3

例如,您必须创建并分配一个包含您要使用的图像的 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;`
于 2014-06-20T07:55:45.600 回答
0

你需要添加一个ImageList到你的TreeView,之后你可以设置一个节点的 withImageKey属性。

于 2014-06-19T18:53:53.323 回答