Flexible TreeView Flexible TreeView


Support & Community

NodeCheckBox node control

Previous Table of Contents Next

The NodeCheckBox node control allows you to show a checkbox or radio button icon inside a node.


Please note that it displays only an image of a checkbox or radio button, without text. To show text, add the NodeTextBox node control after the NodeCheckBox.


To define what type of check to show, use the CheckType node property (has the eCheckType.CheckBox value by default).
By default the node control is bound to the node`s check state that is stored in the CheckState property.

Example:

NodeCheckBox nodecontrol = new NodeCheckBox();
nodecontrol.AttachTo(tree);
 
Node node = new Node(“node title”);
node.CheckState = eCheckState.Checked;
// define the check type for every node.
node.CheckType = eCheckType.RadioButton            // or eCheckType. CheckBox
node.AttachTo(tree);


Change the check state without selecting a node

If you need to change the check state without selecting a node, use this code:

// the node control instance to access it from the event handler later.
private NodeCheckBox checkBox;
 
// create the node control.
checkBox = new NodeCheckBox();
checkBox.AttachTo(tree);
 
// create the node.
Node node = new Node();
node.AttachTo(tree);
 
tree.MouseDown += tree_MouseDown;
 
// process the mouse click on a node.
void tree_MouseDown(FlexibleTreeView pTreeview, MouseActionArgs pArgs)
{
  if (pArgs.NodeControl == checkBox)
  {
    // change the check state manually
    pArgs.Node.CheckState = checkBox.GetNextCheckState(pArgs.Node);
 
    // and skip all further treeview`s actions for this event.
    pArgs.Handled = true;
  }
}


Control check state changes manually

If you want to control a node`s check state manually (for example, to provide non–standard states sequence), you need to create a custom node control class and override the SetNextCheckState method.

Example:

// Custom node control class where we manually replace the Checked check state with Unknown when node`s check state has changed.
class MyNodeCheckBox : NodeCheckBox
{
  // override the check state change logic and replace the Checked state with Unknown.
  protected override void SetNextCheckState(Node pNode)
  {
    // Checked or Unknown –> Unchecked.
    if (pNode.CheckState == eCheckState.Unknown)
    {
      pNode.CheckState = eCheckState.Unchecked;
    }
    // Unchecked –> Unknown.
    else
    {
      pNode.CheckState = eCheckState.Unknown;
    }
  }
}
 
// create our node control.
MyNodeCheckBox nc = new MyNodeCheckBox();
nc.AttachTo(tree);
 
Node node = new Node();
// enable the three check states feature to be able to change to the Unknown state in our node control.
node.ThreeCheckState = true;
node.AttachTo(tree);


Override check icons

By default, NodeCheckBox uses system or Office2007 theme check icons but you are able to override them by using the Images treeview property.

Example:

// change the icon of the checkbox in unchecked state.
tree.Images.CheckboxUnchecked = myUncheckedIcon;
// change the icon of the radio button in checked state.
tree.Images.RadioButtonChecked = myCheckedIcon;


Addional API reference


Properties

  • Editable – defines whether the node control can change the check state.

Previous Top Next


Last news
Bookmark and Share
Use Flexible TreeView in WPF project
Sunday, 18 December 2011

Do you have a WPF project and want to use Flexible TreeView there? No problem!

Flexible TreeView v3.4
Friday, 16 December 2011

Flexible TreeView v3.4 maintenance release has been released.

Flexible TreeView v3.3
Friday, 23 September 2011

Flexible TreeView v3.3 maintenance release has been released. Separate assemblies for .NET 2.0, 4.0 and 4.0 Client Profile, HTML markup extension, etc.

Latest release

Version:
Release date:
3.4
Dec 16, 2011


Copyright © 2006-2012 ARMSoft. All rights reserved.