Click here to Skip to main content
15,881,725 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
actually i have treeview which loaded programatically ,this is 3level treeview

dept
|
|_Subdept
|
|
|__KPI

all these value are loaded from database.I want to showplusminus sign only for dept and subdept node.
What can I do?
Posted

1 solution

Using the Microsoft WinForms TreeView: remember that this Control is a wrapper around the native Window TreeView: showing, or hiding, the plus/minus symbols can be set only for the entire Control.

1. set the TreeView Property 'ShowPlusMinus to false.

2. add an ImageList Control to your Form

3. add images for plus and minus to the ImageList

4. set the TreeView 'ImageList Property to use the ImageList

5. set the ImageIndex Property of selected TreeNodes as desired

6. implement code to detect when TreeNodes you wish to show the Plus/Minus symbols on are expanded, or collapsed by switching the ImageIndex.

Keep in mind that once a valid ImageList is assigned to the TreeView, all Nodes will, by default, display the first image in the ImageList.

That creates a problem: you can't have a Node that has no image. People have found various awkward ways to work-around this: [^].

CodeProject has an article that works around this all-or-nothing images on Nodes problem by creating an owner-drawn TreeView: [^].

Imho, the cost of implementing any of the solutions described above is too high. These kinds of limitations on the MS TreeView are one (of many) reasons I switched to using a commercial third-party TreeView Control (I purchased the IntegralUI TreeView from Lidor Systems).
 
Share this answer
 
v2

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