Problem with image column in XtraTreeList

4.8k Views Asked by At

I use XtraTreeList control.

There are 2 columns: first for text and second for icon

Problem : I can't change default icon (zero index in corresponding imagelist). There are 3 images in imagelist.

For example I need to show icon which is located at 2 index

Code

 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();
2

There are 2 best solutions below

0
On BEST ANSWER

Thanks for everybody

Using RepositoryItemPictureEdit solved my problem. A little bit complex, but works

 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();
5
On

This task should be implemented using slightly different approach. First, you should use the RepositoryItemImageComboBox and populate its Items property. Each item has value and ImageIndex. The TreeList will show in a cell image from the item whose value equals the cell value. Here is the code which should work for you:

        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();