I know how to show a single CheckBox for each TreeNode in a TreeView. I would like to show 3 CheckBoxes for each TreeNode in a TreeView. The reason for this is that there are 3 charts in my program, and each TreeNode represents a different series. I would like to give the user the option of displaying each series on whichever chart they like.
Is this (or something similar) possible? Thanks in advance.
Follow this link to get an idea to add checkbox in a node from the link: https://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.checkboxes%28v=vs.140%29.aspx
You will need to owner-draw a
TreeView
. Not exactly the simplest example of owner-drawing a Control but still not too hard.Here is an example screenshot:
First we create simple
TreeNode
subclass to hold the extra data:Note that I hide the original Text and basically replace it by a string variable Label. I avoid using the
Tag
so you can still make use of it yourself.. I have not implemented all constructors. If you needImageLists
you may want to add those with theImageIndices
.Now for the
TreeView
itself:A few notes:
LabelEditing
. Doable but another can of worms..FullrowSelect
to be true but actually it is in effect anyway..ImageList
andStateImageList
but need to set the indices after the nodes are added.CheckBoxes
property to true! All threeCheckBoxes
are virtual and you access them after casting the nodes toTreeNode3
as itsCheck1..Check3
properties!Console.WriteLines
in the code for better testing..Update I have added a
Spacing
andPadding
property and a few constructors. Now the form code that sets up the example looks pretty normal: