Flexible TreeView Flexible TreeView


Support & Community

Custom node control

Previous Table of Contents Next

If you need specific node controls with custom behavior or appearance, you can easily create them. Depending on what you need, you should inherit your node control class from one of these:

  • BindableControl – for node controls that can bind to a node class`s member;
  • EditableControl – for editable node controls;
  • TextControl – for editable text node controls;
  • StaticTextControl – for non– editable text node controls;
  • PopupControl – for node controls that show popup on mouse click;
  • ExpandableControl – for expandable node controls.


For instance, here we`ll create a node control that is displays the color rectangle inside a node and changes the color on mouse click:

// custom node control class.
class MyNodeControl : BindableControl
{
  public MyNodeControl()
  {
    // bind to the Color node class`s property.
    DataFieldName = "Color";
  }
 
  protected override Size MeasureSize(Node pNode, DrawContext pContext)
  {
    // static node control size.
    return new Size(15, 15);
  }
 
  protected override void Draw(Node pNode, DrawContext pContext)
  {
    // display bounded color.
    Color cl = GetValue<Color>(pNode);
    using (SolidBrush br = new SolidBrush(cl))
    {
      pContext.Graphics.FillRectangle(br, pContext.Bounds);
    }
  }
 
  protected override void MouseDown(MouseActionArgs pArgs, DrawContext pContext)
  {
    // switch color on mouse click.
    Color cl = GetValue<Color>(pArgs.Node);
    Color clNew = (cl == Color.Red) ? Color.Blue : Color.Red;
    SetValue(pArgs.Node, clNew);
    OnControlChanged(eNodeControlChangeType.Look);
    }
}
 
// use our node control.
MyNodeControl nc = new MyNodeControl();
nc.AttachTo(tree);
 
NodeWithColor node = new NodeWithColor();
// initialize bounded property value.
node.Color = Color.Red;
node.AttachTo(tree);

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.