在XtraTreelist的不同节点显示不同的图片,操作实际很简单,在拖放了XtraTreelist放在Panel上后,再向面板拖放一个(Windows.Froms.ImageList)ImageList1,接下来将进行如下设置:
1. 点击ImageList1,选择“Images”属性,向ImageList1添加图片。
2. 点击XtraTreelist,设置以下三个属性:
ColumnsImageList= ImageList1;
SelectImageList= ImageList1;
StateImageList= ImageList1;
3. 新增XtraTreelist事件:CustomDrawNodeImages +=ImageList1_CustomDrawNodeImages;
4. 以上三个步骤是在设计器中设置的,接下来便在ImageList1_CustomDrawNodeImages事件中写代码,例如
private void ImageList1_CustomDrawNodeImages (object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e) {
e.SelectImageIndex = e.Node.Level+1; // e.SelectImageIndex为图片在ImageList中的index
}
*******************************另一种方法************************************
或用代码实现
ImageList SelectTreeImageList = new ImageList();
SelectTreeImageList.ColorDepth = ColorDepth.Depth32Bit;
SelectTreeImageList.ImageSize = new Size(16, 16);
SelectTreeImageList.Images.Add(Image.FromFile(@"F:\zzh\软件类\ico\FACE01.ICO"));
SelectTreeImageList.Images.Add(Image.FromFile(@"F:\zzh\软件类\ico\FACE04.ICO"));
treeList1.SelectImageList = SelectTreeImageList;