Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi..

Can we do like this ?

In treeView for child node I am assigning string value but in that I have to display part of string in Bold format. This part I have to make bold- itemslist[i].Value

TreeNode tn = this.treeViewResult.Nodes.Add(nodeTitle);

for (int i = 0; i < itemslist.Count; i++)
                       {
tn.Nodes.Add("node",itemslist[i].Name+":"+itemslist[i].Value,index); 
}

Please help me...

Thank you
-Dattatrya Moin
Posted
Updated 15-May-12 21:58pm
v2
Comments
Jim Jos 16-May-12 4:12am    
Which platform you are using this treeview? Is it Winforms, WPF or Asp.net

You can't do it by assigning a string value: the TreeView control does not support format codes in node strings.

You can do it, but it is a little more complex: you have to draw the node itself yourself, by handling the DrawNode event and doing the text formatting in the handler. MSDN TreeView.DrawNode[^] - it does include a basic example, which changes the font.
 
Share this answer
 
TreeView itself does not support such customization. But you can set its TreeView.DrawMode property to OwnerDrawText.
Your TreeView will then raise the DrawNode event[^] which you can subscribe to and handle all of the text drawing on your own.

That way you can have GDI+ draw text in whatever fashion you need (Graphics.DrawString() method[^])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900