0

I have treeview with three view nodes in windows forms

That I want to know is if its possible to concat text with image. I mean

Note: Images are current stored in ImageList

This is a node (image here)
Another node (image here)

I try to do something like:

nodes[idx].Text = nodes[idx].Text + nodes[idx].ImageIndex;

But it just do something like:

 This is a node 10
 Another node 10

Instead of use image it put current image index value.

Is it possible to achieve that I want?

Jonathan
  • 601
  • 9
  • 26
  • So you want to concat string and byte? – Hasta Tamang May 02 '19 at 17:40
  • I don't know if ImageCollection return byte, but I do another try like: `nodes[idx].Text = nodes[idx].Text + imgList.Images[1];` and it return `This is a node System.Drawing.Bitmap` @HastaTamang – Jonathan May 02 '19 at 17:48
  • You are entering the OwnerDraw and DrawNode world with that requirement. – LarsTech May 02 '19 at 17:50
  • What is the aversion to using the standard capability - https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-set-icons-for-the-windows-forms-treeview-control - is it a huge problem that the icons are on the left? – Caius Jard May 02 '19 at 18:17
  • That I want to create something like "Tags" next to text, so depending of received values set that tags for example "Reviewed" - "Completed" etc. @CaiusJard – Jonathan May 02 '19 at 18:23

1 Answers1

0

I think what you want to achieve is not so easily possible. The text property can only contain a text string.

One possibility for realiying this is using owner drawn treeviews. This is very complicated, you need to implement the complete text drawing and image drawing on your own. You find more information for example in the following questions:

TreeView with custom drawn TreeNode

How to add icons to TreeView control in c# using OnPaint args

An easier solution might be using unicode Icons, if you only want to show specific standard icons.

        treeView1.Nodes.Add("go to LA ✈");
        var n = treeView1.Nodes.Add("Tasks ❒");
        n.Nodes.Add("Done ✅");
        n.Nodes.Add("Failed ❎");

Preview of treeview

you find a list of symbols on various pages, for example https://en.wikipedia.org/wiki/Dingbat#Unicode

user287107
  • 9,286
  • 1
  • 31
  • 47