Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在TreeListView中为每个对象设置图标_C#_Objectlistview_Treelistview - Fatal编程技术网

C# 如何在TreeListView中为每个对象设置图标

C# 如何在TreeListView中为每个对象设置图标,c#,objectlistview,treelistview,C#,Objectlistview,Treelistview,我有一些图标应该显示在RowObject名称旁边的第一列中。 不同的图片与不同类型的身体有关。 这部分代码使用我需要的对象创建列 this.descriptionTView = new BrightIdeasSoftware.TreeListView(); this.descriptionTView.CanExpandGetter = x => { if ( ( x as ITreeViewItem ).Items != null ) {

我有一些图标应该显示在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.descriptionView=新的BrightIdeasSoftware.TreeListView();
this.descriptionView.CanExpandGetter=x=>
{
if((x为ITreeViewItem).Items!=null)
{
返回(x作为ITreeViewItem)。Items.Length>0;
}
其他的
{
返回false;
}
};                
this.descriptionView.ChildrenGetter=x=>(x作为ITreeViewItem);
var column1=新的BrightIdeasSoftware.OLVColumn(“,”第0部分”);
column1.AspectGetter=x=>(x作为ITreeViewItem);
column1.IsEditable=true;
var column2=新的BrightIdeasSoftware.OLVColumn(“第1部分”);
column2.AspectGetter=x=>(x作为ITreeViewItem);
column1.IsEditable=true;
column2.IsEditable=true;
this.descriptionView.Columns.Add(column1);
this.descriptionView.Columns.Add(column2);
私人物品清单;
descriptionView.root=itemsList;

您需要将
图像列表添加到
树视图
,然后您可以使用
图像键
属性设置节点。

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

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;`

我相信这就是你要找的。你能添加更多的细节并发布你的代码片段吗?没有信息就无法帮助您。在ObjectListView中,我们不使用TreeNode或节点,而是添加不同的对象。我不使用节点。我的对象不包含ImageKey属性。谢谢。你真的帮了我。