我有一些图标应该显示在 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;
最佳答案
例如,您必须创建并分配一个包含您要使用的图像的 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;`
关于c# - 如何为TreeListView中的每个对象设置一个图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24313897/