Flexible TreeView Flexible TreeView


Support & Community

Data binding

Previous Table of Contents Next

To display data inside a node control, you need to bind that node control to the appropriate data. A node control may have two data binding types – static and dynamic (virtual).

 

Static data binding

With static data binding, the node control displays a node class member`s value with a known name, stored in the DataFieldName node control property. To enable static data binding, fill the DataFieldName property and disable the VirtualMode property (disabled by default). Note that the node control may be bound to a node class`s property or a field. 


Node controls supported data types

The bound node class member`s type should be one supported by the node control.

NodeTextBox - all types through converting to the string using the ToString method.
NodeComboBox - int or enum.
NodeImage - System.Drawing.Bitmap with 32 bits per pixel.
NodeCheckBox - ARMSoft.FlexibleTreeView.eCheckState enum.
NodeNumeric - decimal, float, double, int, long.
NodeExpandableTextBox.Title - string.
NodeExpandableTextBox.Description - string.
NodeExpandablePanel.Title - string.
NodeColorPicker -  System.Drawing.Color for the solid color or ARMSoft.FlexibleTreeView.ColorGradient for the color gradient.
NodeControlContainer - System.Windows.Control.
NodeExpandableControlContainer - System.Windows.Control.
NodeLink - string.
NodePaintBox - Any custom drawing content.
NodePopupContainer - System.Windows.Control.
NodeDateTime - DateTime.
NodeProgressBar - int.
NodeSeparator - none.

You can bind to any node`s member, either the built-in or own.

Example:

// add text and image node controls.
// the text node control bound to the built-in Text node property by default.
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
 
NodeImage img = new NodeImage();
// bind the image node control to the own node`s member.
img.DataFieldName = "Image";
img.AttachTo(tree);
 
NodeEx node = new NodeEx("Node title");
node.Image = Resources.SomeImage;
node.AttachTo(tree);

 

Dynamic (virtual) data binding

With dynamic or virtual data binding, the data source is not known at the compile time and would be defined in run–time for every node.
To enable dynamic data binding, enable the VirtualMode node control property and subscribe to the NodeControlValueGet and the NodeControlValueSet treeview events, where you will provide (NodeControlValueGet) data to display or save (NodeControlValueSet) changes.

Example:

NodeTextBox tb = new NodeTextBox();
tb.VirtualMode = true;
// even if this node control is in virtual binding mode we fill the bound property name, where data will be gained if not supplied in the NodeControlValueGet  event.
tb.DataFieldName = "Text";
tb.AttachTo(tree);
 
// add node with a title that is dynamically generated in run-time.
Node node = new Node();
node.Tag = 1;
node.AttachTo(tree);
 
// even if the virtual mode is enabled, you can add nodes with a static title (see tree_NodeControlValueGet below)!
node = new Node("Node with static title");
node.Tag = null;
node.AttachTo(tree);
 
tree.NodeControlValueGet += tree_NodeControlValueGet;
tree.NodeControlValueSet += tree_NodeControlValueSet;
 
bool tree_NodeControlValueGet(FlexibleTreeView pTreeview, NodeControlValueEventArgs pArgs)
{
  // return dynamic node`s title for those nodes that we need.
  if (pArgs.Node.Tag != null)
  {
    pArgs.Value = "Node title";
    return true;
  }
 
  // tell treeview to retrieve data from the node`s property which name is in the DataFieldName node control property.
  return false;
}
 
private void tree_NodeControlValueSet(FlexibleTreeView pTreeview, NodeControlValueEventArgs pArgs)
{
  // save changes here.
}

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.