Flexible TreeView Flexible TreeView


Support & Community

Owner drawing

Previous Table of Contents Next

You can partially or completely override a node control`s appearance. To do that, you need to inherit your node control class from any core node control and override its appearance as stated below.

Example:

Here we derive our class from the core node control BindableControl (that allows you to bind the node control to a node class`s member) and design our node control appearance manually. Note that this is a very basic sample and you can use the NodePaintBox node control for that purpose.

// The node control for displaying a color rectangle which color is in a node instance.
class MyNodeControl : BindableControl
{
  public MyNodeControl()
  {
    // bind this node control to the Color node property.
    DataFieldName = "Color";
  }
 
  // measure the control`s occupied area size inside a node.
  protected override Size MeasureSize(Node pNode, DrawContext pContext)
  {
    // make static size but you can provide dynamic size as well.
    return new Size(20, 20);
  }
 
  // draw the node control content.
  protected override void Draw(Node pNode, DrawContext pContext)
  {
    Color cl;
 
    cl = GetColor(pNode);
    using (SolidBrush br = new SolidBrush(cl))
    {
      pContext.Graphics.FillRectangle(br, pContext.Bounds);
    }
  }
 
  // get the bound data value.
  Color GetColor(Node pNode)
  {
    return GetValue<Color>(pNode);
  }
}
 
// use our custom node control.
MyNodeControl ctrl = new MyNodeControl();
ctrl.AttachTo(tree);
 
// add nodes.
for(int i = 0; i < 50; i++)
{
  NodeWithColor node = new NodeWithColor();
  // initialize the color that the node control will display.
  node.Color = ((i%3) == 0) ? Color.Red : Color.Green;
  node.AttachTo(tree);
}
 
tree.Options.Node.AutoNodeHeight = true;

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.