Flexible TreeView Flexible TreeView


Support & Community

Data binding. Inspection

Previous Table of Contents Next


Validation

During binding of the data source all of the public properties (as columns and node controls) and objects (as nodes) located in the data source will be added to the treeview. Flexible TreeView will also let you perform a validation of these added to the treeview objects. In order to perform this task, turn on the Validate property of the DataBinding object and subscribe to the ColumnPopulating, NodeControlPopulating and NodePopulating events.


ColumnPopulating event

ColumnPopulating event allows validating added to the treeview columns which are formed out of the data source object properties. You can refuse to add such column in the event handler by setting value of the Cancel property to TRUE.

Example:

void tree_ColumnPopulating(FlexibleTreeView pTreeview, ColumnPopulatingEventArgs pArgs)
{
  if (pArgs.FieldName == "SomeField")
  {
    pArgs.Cancel = true;
  }
}


NodeControlPopulating event

NodeControlPopulating event allows validating added to the treeview node controls which are formed out of the data source object properties. You can refuse to add such node control in the event handler by setting value of the Cancel property to TRUE.


NodePopulating event

NodePopulating event allows validating added to the treeview nodes which are formed out of the data source objects. You can refuse to add such node in the event handler by setting value of the Cancel property to TRUE.


Lazy load (load on demand)

By default, Flexible TreeView creates nodes for all of the objects in a data source. If you require a lazy load (in order to speed up loading of the data source) for any node, you can perform this task by subscribing to the NodePopulating event. In the event handler you need to cancel the process of adding to the tree view all of the nodes which have to be loaded later, by setting value of the Cancel parameter to TRUE, as well setting the LoadOnDemand to TRUE for all nodes, which children you need to load later.

Example:

void tree_NodePopulating(FlexibleTreeView pTreeview, NodePopulatingEventArgs pArgs)
{
  // for all nodes enable lazy load because we don`t know whether this node has children.
  pArgs.Node.LoadOnDemand = true;
 
  // do not add all non-root nodes but load them later.
  if (pArgs.ParentNode != null)
  {
    pArgs.Cancel = true;
  }
}
 
// lazy load.
private void tree_NodeExpanding(FlexibleTreeView pTreeview, NodeExpandingEventArgs pArgs)
{
  // lazy load for the child node.
  if (pArgs.Node.LoadOnDemand)
  {
    // disable lazy load for the loaded nod.
    pArgs.Node.LoadOnDemand = false;
 
    // load node`s children here...
  }
}

See below in order to find out how to add own nodes to the tree view with bound data source.


Add custom columns, node controls, nodes into a bound treeview

Many treeview controls after binding of the data source represent black-box and do not allow user any changes or additions. Flexible TreeView on the other hand, will allow you to fully customize the treeview even after binding of the data source in bound mode as well as in unbound mode.


Add column and node controls

If you need to add your own columns or node controls to the treeview, you can do that the same way is it was done before, by adding the TreeColumn instance in to the Columns property or NodeControl (or an inheritor) instance in to the NodeControls property.


Add node

Flexible TreeView works with bound data according to the binding mode - bound or unbound.
In bound mode Flexible TreeView stores only references to the bound objects and changes data directly. In unbound mode Flexible TreeView copies all of the fields of the bound object which needs to be shown.
Each node in a treeview, to which a data source is bound to, inherits from the BindableNode type, which allows an object to be bound to a data source as well as to store all of its fields.
Thus, the method of adding the node to a treeview will solely depend on binding type with a data source.

Further we will be using data source - list, including instances of some Order class:

class Order
{
  ......
}


Add node in bound mode

Let's assume that after binding of the data source we need to add one more object type Order in to the data source and in to a treeview. In order to perform this task let's create a new object and add it in to data source:

Order order = new Order();
list.Add(order);    // here ‘list’ – is our data source.
 
// Then let's add a new object in to a tree view, by creating the BindableNode class instance and passing in to the constructor our new object of Order type.
BindableNode node = new BindableNode("object id here", order);
node.AttachTo(tree);

Note, instead of "object id here" parameter you need to pass a value of unique identifier of the new object. Its type string was used in here only for example.

That is it! New object is added to the treeview.

Note, you do not need to add new objects also in to your data source! All you need is to pass it into the node constructor.


Add node in unbound mode

In unbound mode situation is the same as in bound mode, but creating of the node should be done by using other constructor, where you should pass a Dictionary<string, object>, which have to include names of the properties showing in the tree view and their values:

// We can acquire list of the properties and their values by using the DataSourceManager class.
Dictionary<string, object> fieldValues = DataSourceManager.Current.GetFieldValues(order);
 
// Create and add new node.
BindableNode node = new BindableNode("object id here", fieldValues);
node.AttachTo(tree);

Note, instead of "object id here" parameter you need to pass a value of unique identifier of the new object. Its type string was used in here only for example.

Also note, all of changes made by user in to the treeview will not be shown in your object if it is done in the unbound mode.

 


If you need to add nodes, which will be bound with instances not of the Order type, you can do that, by following instructions above, while using instance of your type, but your data type have to have same properties as Order type.




Add node without linked object

You can also add to the treeview a virtual object, supplying needed date yourself without creation of the instance. In order to do that you need to inherit a class from BindableNode and override GetBoundFieldValue and SetBoundFieldValue methods as shown bellow.

class VirtualBindableNode : BindableNode
{
  protected override object GetBoundFieldValue(string pFieldName)
  {
    // return object`s data here.
  }
 
  protected override void SetBoundFieldValue(string pFieldName, object pValue)
  {
    // save object`s data 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.