Flexible TreeView Flexible TreeView


Support & Community

Data binding. Prepare data source

Previous Table of Contents Next

Supported data types

Flexible TreeView supports binding of the following data types:

  • Boolean or ARMSoft.FlexibleTreeView.Nodes.eCheckState;
  • Color;
  • Bitmap with 32 bit per pixel;
  • int/long/decimal/float;
  • string;
  • DateTime.

During binding of the data source to the treeview, you have the following options to manage binding results of your data source.


Bidirectional binding mode

Flexible TreeView imposes special conditions on the type and behavior of data source in bidirectional binding mode! Please read the topic 'Bidirectional binding mode' for details.


Hierarchy

Flexible TreeView supports binding of the plain data sources as well as the hierarchical ones.
In order to create hierarchical data source you need to add in to the object type which consists the data source two properties, where you would store an identifier of the object itself (Id for example) and of the parent object (ParentId for example). Then you need to set the names of these properties in the KeyFieldName and ParentFieldName properties of the DataBinding object accordingly.

Example:

class Order
{
  private int m_Id;
 
  public int Id
  {
    get { return m_Id; }
    set { m_Id = value; }
  }
 
  private int? m_ParentId;
 
  public int? ParentId
  {
    get { return m_ParentId; }
    set { m_ParentId = value; }
  }
 
  private string m_Number;
 
  public string Number
  {
    get { return m_Number; }
    set { m_Number = value; }
  }
}

 


Note that the ParentId property can take a NULL value for the root objects in the hierarchy.

 

Data source usage (for example, we use the List<T> data source type) example:

List<Order> list = new List<Order>();
 
// create root object.
Order order = new Order();
order.Id = 1;
// NULL parent for all root objects.
order.ParentId = null;
order.Number = "No.1";
list.Add(order);
 
// create child object.
order = new Order();
order.Id = 2;
// specify parent identifier for the child object.
order.ParentId = 1;
order.Number = "No.1.1";
list.Add(order);
 
 
// define hierarchy member names.
tree.DataBinding.KeyFieldName = "Id";
tree.DataBinding.ParentFieldName = "ParentId";
 
// attach data source to the treeview.
tree.DataBinding.DataSource = list;


DataBindingElementAttribute

Visible

By default, Flexible TreeView will add to the treeview all public properties (as columns and node controls) of the data source object. If you have an access to the source code of the object class, stored in the data source, you can use the DataBindingElementAttribute attribute in order to control the property visibility within Flexible TreeView. In order to prevent Flexible TreeView from adding property in to the treeview, you need to apply DataBindingElementAttribute atribute to it and set value of the Visible parametr to FALSE.

Example:

class Order
{
  private int m_Id;
 
  public int Id
  {
    get { return m_Id; }
    set { m_Id = value; }
  }
 
  private int? m_ParentId;
 
  public int? ParentId
  {
    get { return m_ParentId; }
    set { m_ParentId = value; }
  }
 
  private string m_Number;
 
  public string Number
  {
    get { return m_Number; }
    set { m_Number = value; }
  }
 
  private decimal m_Sum;
 
  [DataBindingElement(Visible = false)]
  public decimal Sum
  {
    get { return m_Sum; }
    set { m_Sum = value; }
  }
}

The Sum property will not be processed by the Flexible TreeView parser in here, that is why such column will not appear in the treeview.


DisplayName

By default, Flexible TreeView generates separate column for every field of the data object.
Also, you can customize the column caption created from the bound property. To do that, set the custom caption in the DisplayName property of the DataBindingElementAttribute.

Example:

[DataBindingElement(DisplayName = "Custom caption")]
public decimal Sum
{
  get { return m_Sum; }
  set { m_Sum = value; }
}

Note that if the DisplayName property has the same value for several data object fields, all these fields will be displayed in one column with the caption indicated in DisplayName. In this case the order they are displayed in the column will be identical to a sequence order of the fields in a data object class.


AutoSizeColumn

By using the DataBindingElementAttribute attribute you can also preset to have the width of a generated column calculated automatically based on the content in this column. To get this you have to enable the AutoSizeColumn property:

class Order
{
  [DataBindingElement(AutoSizeColumn = true)]
  public decimal Sum
  {
    get { return m_Sum; }
    set { m_Sum = value; }
  }
}

IsCheckState

The DataBindingElementAttribute.IsCheckState is intended to support interactive check state when treeview is in bound mode.


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.