Friday, March 5, 2010

Complex and a special three state (tri state) Treeview Control

As we all know treeview is used to show hierarchy of items easily. Microsoft tree is readily available for you if your needs are simple. But if you want to have the tree do more than two states it might not be possible with the treeview control as it is. You might have seen several treeview .net controls out there that have three states but the treeview in this post here might be little different than those. A parent can have its own state and can depict its child check state when stateless, also all the children under a parent are not affected when check state on the parent changes.

States:
Checked – Green Check
Unchecked – No Check
AtLeastOneChild Checked (only for Parent) – Light Gray Check

State Determination:

Node when checked a green check is shown regardless of whether any child nodes have been checked
Node when unchecked but has checked child, gray check is shown for the node.
Node when unchecked and has no children or all children unchecked, an empty check is shown

State Images:






What it can do:

Bind to Any Type of DataSource
Bind to a Single Datasource (With node definition and its check state)
Bind to Two Datasources(One that has node definition and other that has check state of the nodes)
Select All
Deselect All
Expand All
Collapse All
Read-only
Undo
Redo
Escape on a node gets previous check state back
Enter Select the node
Node color change on editing
Configurable coloring scheme for read-only and edited nodes

Using It:

For the treeview to properly work you have to set the members(columns in your binding objects)

ParentIDMember - Column to determine heirarchy
ValueMember – Column that holds the ID of the node
DisplayMember – Column that holds the Node Text
DefinitionValueRelationshipMember – Column that is common in the definition object and value object
DefinitionEntityCheckValueMember – Column that determines the check state of the node in the definition
ValueEntityCheckValueMember - Column that determines the check state of the node in the value object
CheckBoxEnabledMember – Column to enable/disable the node

Loading Nodes And Values

a)With no node values in the definition
TriStateTreeView1.DefinitionHasValue = False
TriStateTreeView1.DisplayMember = "Name"
TriStateTreeView1.ValueMember = "ID"
TriStateTreeView1.ParentIDMember = "ParentID"
TriStateTreeView1.CheckBoxEnabledMember = "CheckBoxEnabled"

TriStateTreeView1. ValueEntityCheckValueMember = “NodeValue”
TriStateTreeView1. DefinitionValueRelationshipMember = “ID”
TriStateTreeView1.BindNodesDataSource(lst)
TriStateTreeView1.BindNodeValuesDataSource(lstValues)

b)With node values in the definition

TriStateTreeView1.DefinitionHasValue = True
TriStateTreeView1.DisplayMember = "Name"
TriStateTreeView1.ValueMember = "ID"
TriStateTreeView1.ParentIDMember = "ParentID"
TriStateTreeView1.CheckBoxEnabledMember = "CheckBoxEnabled"
TriStateTreeView1.DefinitionEntityCheckValueMember = “NodeValue”
TriStateTreeView1.BindNodesDataSource(lst)

Link below has the control and the sample code on how to use the control.

No comments:

Post a Comment

IIS Manager Crashes on Load/Start Windows 7, IIS 7.5

IIS Manager Crashes on Start  Windows 7, IIS 7.5, Power Shell 5.1. Here is the error I got in the event viewer. IISMANAGER_CRASH IIS Ma...