几年不用Devexpress,居然TreeList设置图标都忘记怎么弄了,记录下
1、窗口上拖动一个TreeList和一个ImageCollection
2、设置ImageCollection图像
3、设置
4、代码如下
public Form1() { InitializeComponent(); //TreeListNode treeNode = new TreeListNode(); //treeNode.ImageIndex = 0; //treeNode.SetValue("ID", "111"); //treeList1.Nodes.Add(treeNode); List<DataSingle> dataSingles = new List<DataSingle>(); DataSingle dataSingle = new DataSingle(); dataSingle.ID = 1111; dataSingle.TEXT = "22222"; dataSingle.ImgIndex = 0; dataSingles.Add(dataSingle); treeList1.DataSource = dataSingles; } public class DataSingle { public int ID { get; set; } public string TEXT { get; set; } public int ImgIndex { get; set; } }
private void treeList1_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e) { if(e.Node.GetValue("ImgIndex")!=null) e.SelectImageIndex = int.Parse(e.Node.GetValue("ImgIndex").ToString()); }
5、结果