我使用XtraTreeList控件。
有两列:第一列是文字,第二列是图标
问题:我无法更改默认图标(相应图像列表中的零索引)。 imagelist中有3张图片。
例如,我需要显示位于2索引的图标
代码
TreeListColumn col = treeList1.Columns.Add();
col.Caption = "Text";
col.Visible = true;
TreeListColumn colImage = treeList1.Columns.Add();
colImage.Caption = "ImageColumn";
colImage.Visible = true;
RepositoryItemImageEdit imageEdit = new RepositoryItemImageEdit();
imageEdit.Images = imageList;
treeList1.RepositoryItems.Add(imageEdit);
colImage.ColumnEdit = imageEdit;
treeList1.BeginUnboundLoad();
TreeListNode node = treeList1.AppendNode(new object[] { "trololo", 2}, null);
node.SetValue(colImage.AbsoluteIndex, 2);
treeList1.EndUnboundLoad();
答案 0 :(得分:1)
感谢大家
使用RepositoryItemPictureEdit解决了我的问题。有点复杂,但有效
TreeListColumn col = treeList1.Columns.Add();
col.Caption = "Text";
col.Visible = true;
TreeListColumn colImage = treeList1.Columns.Add();
colImage.Caption = "ImageColumn";
colImage.Visible = true;
RepositoryItemPictureEdit imageEdit = new RepositoryItemPictureEdit();
imageEdit.ShowMenu = false;
treeList1.RepositoryItems.Add(imageEdit);
colImage.ColumnEdit = imageEdit;
treeList1.BeginUnboundLoad();
Image img = imageList.Images[1];
Bitmap bmp = new Bitmap(img);
TreeListNode node = treeList1.AppendNode(new object[] { "trololo", bmp }, null);
treeList1.EndUnboundLoad();
答案 1 :(得分:0)
此任务应使用略有不同的方法实施。首先,您应该使用RepositoryItemImageComboBox并填充其Items属性。每个项目都有值和ImageIndex。 TreeList将显示来自项目的单元格图像,该项目的值等于单元格值。以下是适合您的代码:
TreeListColumn col = treeList1.Columns.Add();
col.Caption = "Text";
col.Visible = true;
TreeListColumn colImage = treeList1.Columns.Add();
colImage.Caption = "ImageColumn";
colImage.Visible = true;
RepositoryItemImageComboBox imageEdit = new RepositoryItemImageComboBox();
imageEdit.SmallImages = imageList;
for(int i = 0; i < 3; i++)
imageEdit.Items.Add(new ImageComboBoxItem(i, i)); // i.e. value and image index
treeList1.RepositoryItems.Add(imageEdit);
colImage.ColumnEdit = imageEdit;
treeList1.BeginUnboundLoad();
TreeListNode node = treeList1.AppendNode(new object[] { "trololo", 2 }, null);
node.SetValue(colImage.AbsoluteIndex, 2);
treeList1.EndUnboundLoad();