1

我使用 XtraTreeList 控件。

有 2 列:第一列用于文本,第二列用于图标

问题:我无法更改默认图标(相应图像列表中的零索引)。图像列表中有 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();
4

2 回答 2

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();
于 2011-04-07T09:40:11.950 回答
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();
于 2011-04-07T07:48:48.163 回答