Skip to content

Data binding

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 node control property and disable the VirtualMode node control property (disabled by default).

Note

The node class member's name specified in the DataFieldName node control property can be a property or field name, and it is case-sensitive.

Supported data types#

Bound node class member's type must be one supported by the node control.

  • NodeTextBox - any type through convertion to string using the ToString method.
  • NodeComboBox - int or enum.
  • NodeComboBoxEnum - enum.
  • NodeImage - System.Drawing.Bitmap with 32-bits per pixel.
  • NodeCheckBox - ARMSoft.FlexibleTreeView.Nodes.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.Themes.ColorGradient for the color gradient.
  • NodeControlContainer - System.Windows.Control.
  • NodeExpandableControlContainer - System.Windows.Control.
  • NodeLink - string.
  • NodePaintBox - any custom drawn content.
  • NodePopupContainer - System.Windows.Control.
  • NodeDateTime - DateTime.
  • NodeProgressBar - int, System.Drawing.Color and ColorGradient.
  • NodeSeparator - none.
  • NodeColumnBackground - System.Drawing.Color.
  • NodeButton - string and System.Drawing.Size.

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

Example

// Add the text and image node controls.
// The text node control bound to the built-in Text node property by default.
NodeTextBox tb = new NodeTextBox();
tb.DataFieldName = "Text";
tb.AttachTo(tree);

NodeImage img = new NodeImage();
// Bind the image node control to a node's custom member.
img.DataFieldName = "Image";
img.AttachTo(tree);

NodeEx node = new NodeEx("Node title");
node.Image = Resources.SomeImage;
node.AttachTo(tree);
' Add the text and image node controls.
' The text node control bound to the built-in Text node property by default.
Dim tb As New NodeTextBox()
tb.DataFieldName = "Text"
tb.AttachTo(tree)

Dim img As New NodeImage()
// Bind the image node control to a node's custom member.
img.DataFieldName = "Image"
img.AttachTo(tree)

Dim node As 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 must provide the data to display (NodeControlValueGet) or save its changes (NodeControlValueSet).

Example

NodeTextBox tb = new NodeTextBox();
tb.VirtualMode = true;
// set bound property name for fallback data source in virtual binding mode if NodeControlValueGet event returns false.
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 treeview, NodeControlValueEventArgs args)
{
    // return dynamic node's title for nodes that we need.
    if (args.Node.Tag != null)
    {
        args.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 treeview, NodeControlValueEventArgs args)
{
    // save changes here.
}
Dim tb As New NodeTextBox()
tb.VirtualMode = True
' set bound property name for fallback data source in virtual binding mode if NodeControlValueGet event returns false.
tb.DataFieldName = "Text"
tb.AttachTo(tree)

' add node with a title that is dynamically generated in run-time.
Dim node As 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 = Nothing
node.AttachTo(tree)

tree.NodeControlValueGet += tree_NodeControlValueGet
tree.NodeControlValueSet += tree_NodeControlValueSet

Private Function tree_NodeControlValueGet(treeview As FlexibleTreeView, args As NodeControlValueEventArgs) As Boolean
    ' return dynamic node's title for nodes that we need.
    If args.Node.Tag IsNot Nothing Then
        args.Value = "Node title"
        Return True
    End If

    ' tell treeview to retrieve data from the node's property which name is in the DataFieldName node control property.
    Return False
End Function

Private Sub tree_NodeControlValueSet(treeview As FlexibleTreeView, args As NodeControlValueEventArgs)
    ' save changes here.
End Sub