Flexible TreeView 5.1.9 Help
Visibility inside the node

Flexible TreeView has these ways to control the node control visibility inside a node:

Read about these modes below and choose which one is appropriate for you.


Visible property

You can control the node control's visibility using the Visible property (enabled by default).
If the node control is not visible (Visible=false), all other visibility's settings do not taken into account!


Node control filtration

By default, every node control in the treeview is visible in every node, but you can control the node control's visibility using the node control filtration. The node control filtration mode is useful when you definitely know which node control for which node to show or hide (static mode), or if you want to make the decision dynamically (dynamic mode).
To do that, adjust one of the filter modes to the Options.NodeControl.NodeControlFilterMode treeview property and decide for which nodes to hide node controls as stated below.
Available filter modes:

The node control filtration mode is useful when you definitely know which node control for which node to show or hide (static mode), or if you want to make the decision dynamically (dynamic mode).


Static filtration

If you know what node control to hide for which nodes, then use static node control filtration, which is the fastest way to filter. To enable it, set the Options.NodeControl.NodeControlFilterMode treeview property to eNodeControlFilterMode.Static value and use the indexer of the NodeControlFilter treeview property to set the node control's visibility for particular nodes.
Available visibility modes:

Example:

Here we'll hide the image node control in the child node while show it in the root node.

// add two node controls to show an image and text.
NodeImage img = new NodeImage();
img.AttachTo(tree);
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
 
// add parent and child nodes.
NodeWithImage root = new NodeWithImage("Root node", Resources.SomeImage);
root.AttachTo(tree);
// bind the same image to the child node too to demonstrate that it will be hidden by visibility settings.
NodeWithImage child = new NodeWithImage("Child node", Resources.SomeImage);
child.AttachTo(root);
// hide the image node control in the child node.
tree.NodeControlFilter[child, img] = eNodeControlVisibility.Hidden;
 
// enable static visibility filtration.
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Static;
' add two node controls to show an image and text.
Dim img As New NodeImage()
img.AttachTo(tree)
Dim tb As New NodeTextBox()
tb.AttachTo(tree)

' add parent and child nodes.
Dim root As New NodeWithImage("Root node", Resources.SomeImage)
root.AttachTo(tree)
' bind the same image to the child node too to demonstrate that it will be hidden by visibility settings.
Dim child As New NodeWithImage("Child node", Resources.SomeImage)
child.AttachTo(root)
' hide the image node control in the child node.
tree.NodeControlFilter(child, img) = eNodeControlVisibility.Hidden

' enable static visibility filtration.
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.[Static]


Dynamic filtration

If you don't know for which nodes to hide node controls, then you can use dynamic filtration. To do that, set the Options.NodeControl.NodeControlFilterMode treeview property to eNodeControlFilterMode.Dynamic value and subscribe to the FilterNodeControl treeview event, where you can then decide whether to show a specified node control inside a specified node.

Example:

// add node controls to show an image and text.
NodeImage img = new NodeImage();
img.AttachTo(tree);
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
 
// add parent and child nodes.
NodeWithImage root = new NodeWithImage("Root node", Resources.SomeImage);
root.AttachTo(tree);
NodeWithImage child = new NodeWithImage("Child node", Resources.SomeImage);
child.AttachTo(root);
 
// activate dynamic node control filtration.
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Dynamic;
 
// subscribe to the event where we'll decide whether to show the node control inside the node.
tree.FilterNodeControl += tree_FilterNodeControl;
 
void tree_FilterNodeControl(FlexibleTreeView pTreeview, FilterNodeControlEventArgs pArgs)
{
  // hide the image node control in the child node.
  if (pArgs.Node.Text == "Child node" && pArgs.NodeControl is NodeImage)
  {
    pArgs.ControlVisibility = eNodeControlVisibility.Hidden;
  }
}
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Static;
' add node controls to show an image and text.
Dim img As New NodeImage()
img.AttachTo(tree)
Dim tb As New NodeTextBox()
tb.AttachTo(tree)

' add parent and child nodes.
Dim root As New NodeWithImage("Root node", Resources.SomeImage)
root.AttachTo(tree)
Dim child As New NodeWithImage("Child node", Resources.SomeImage)
child.AttachTo(root)

' activate dynamic node control filtration.
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Dynamic

' subscribe to the event where we'll decide whether to show the node control inside the node.
tree.FilterNodeControl += tree_FilterNodeControl

Private Sub tree_FilterNodeControl(pTreeview As FlexibleTreeView, pArgs As FilterNodeControlEventArgs)
    ' hide the image node control in the child node.
    If pArgs.Node.Text = "Child node" AndAlso TypeOf pArgs.NodeControl Is NodeImage Then
        pArgs.ControlVisibility = eNodeControlVisibility.Hidden
    End If
End Sub

tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.[Static]


UseVisibility

When you need to have different node control visibility based just on the target node's selection state (like selected, focused, etc.) enable the UseVisibility filtration mode and set the Visibility node control property with a value that defines for which node selection states to display this node control. Note that multiple values can be used when assigning the Visibility property.

Example:

// add node controls to show an image and text.
NodeImage img = new NodeImage();
img.AttachTo(tree);
// show the image node control only within either selected or focused nodes.
img.Visibility = eObjectVisibility.SelectedNode | eObjectVisibility.FocusedNode
 
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);
 
// add some nodes.
NodeWithImage node1 = new NodeWithImage("Root node", Resources.SomeImage1);
node1.AttachTo(tree);
NodeWithImage node2 = new NodeWithImage("Root node", Resources.SomeImage2);
node2.AttachTo(tree);
 
// set node control filtration mode.
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.UseVisibility;
' add node controls to show an image and text.
Dim img As New NodeImage()
img.AttachTo(tree)

' show the image node control only within either selected or focused nodes.
img.Visibility = eObjectVisibility.SelectedNode Or eObjectVisibility.FocusedNode

Dim tb As New NodeTextBox()
tb.AttachTo(tree)

' add some nodes.
Dim node1 As New NodeWithImage("Root node", Resources.SomeImage1)
node1.AttachTo(tree)
Dim node2 As New NodeWithImage("Root node", Resources.SomeImage2)
node2.AttachTo(tree)

' set node control filtration mode.
tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.UseVisibility


Visibility and VisibilityManager

Generally, the node control's visibility is controlled by the Visible node control property. So, you can either show or hide the node control. Also, you can control the node control's visibility using the node control filtration feature. But all those methods do not take into account a node's state for which the node control should be shown. For instance, if you want to display a particular node control only for selected nodes.
To solve that, node control provides a way to define a node's states (selected, focused, etc.) for which to display it in the node. To define these states, use the Visibility and VisibilityManager node control properties. Note that you can define more than one state combining the eObjectVisibility enum items.

The Visibility property allows you to define a node's states for every node control separately.

Example:

NodeTextBox tb = new NodeTextBox();
// show this node control for selected nodes and general (not selected, not focused, etc.) nodes.
tb.Visibility = eObjectVisibility.SelectedNode | eObjectVisibility.GeneralNode;
tb.AttachTo(tree);
 
NodeTextBox tb = new NodeTextBox();
// show this node control only for the selected or under the mouse cursor node.
tb.Visibility = eObjectVisibility.SelectedNode | eObjectVisibility.HotNode;
tb.AttachTo(tree);
Dim tb As New NodeTextBox()
' show this node control for selected nodes and general (not selected, not focused, etc.) nodes.
tb.Visibility = eObjectVisibility.SelectedNode Or eObjectVisibility.GeneralNode
tb.AttachTo(tree)

Dim tb As New NodeTextBox()
' show this node control only for the selected or under the mouse cursor node.
tb.Visibility = eObjectVisibility.SelectedNode Or eObjectVisibility.HotNode
tb.AttachTo(tree)

The VisibilityManager allows you to control many node controls' visibility from one point as ControlContainer does.

Example:

// create the visibility manager.
ObjectVisibilityManager visManager = new ObjectVisibilityManager();
 
// create the first node control.
NodeTextBox ctrl1 = new NodeTextBox();
// attach the visibility manager.
ctrl1.VisibilityManager = visManager;
ctrl1.AttachTo(tree);
 
// create the second node control.
NodeImage ctrl2 = new NodeImage();
// attach the visibility manager.
ctrl2.VisibilityManager = visManager;
ctrl2.AttachTo(tree);
 
// show all bound node controls only in the focused node.
visManager.Visibility = eObjectVisibility.FocusedNode;
 
// temporary disable the visibility manager and use the
// nodeControl.Visibility property value instead.
visManager.Enabled = false;
ctrl1.Visibility = eObjectVisibility.FocusedNode;
ctrl2.Visibility = eObjectVisibility.HotNode;
' create the visibility manager.
Dim visManager As New ObjectVisibilityManager()

' create the first node control.
Dim ctrl1 As New NodeTextBox()
' attach the visibility manager.
ctrl1.VisibilityManager = visManager
ctrl1.AttachTo(tree)

' create the second node control.
Dim ctrl2 As New NodeImage()
' attach the visibility manager.
ctrl2.VisibilityManager = visManager
ctrl2.AttachTo(tree)

' show all bound node controls only in the focused node.
visManager.Visibility = eObjectVisibility.FocusedNode

' temporary disable the visibility manager and use the
' nodeControl.Visibility property value instead.
visManager.Enabled = False
ctrl1.Visibility = eObjectVisibility.FocusedNode
ctrl2.Visibility = eObjectVisibility.HotNode


IsVisibleForNode method

If you need to manually control the node control visibility for every single node, you can override the IsVisibleForNode node control method.

To tell the treeview to use this method, you need to enable the node control filtration (either the static or dynamic mode. Static mode is preferable.) using the NodeControlFilterMode treeview property!

You should return from the IsVisibleForNode method one of these values:

Note that the result of this method has priority over all other settings if it returns 0 or 1 values.


To manually control the node control visibility, derive a new node control class from the built-in one and override the IsVisibleForNode method as stated below:

// declare new node control.
class NodeTextBoxEx : NodeTextBox
{
  protected override int IsVisibleForNode(Node pNode)
  {
    // display this node control only for nodes with children.
    if (pNode.HasChildren)
    {
      return 1;
    }
    return -1;
  }
}
 
// use our node control.
NodeTextBoxEx tb = new NodeTextBoxEx();
tb.AttachTo(tree);
' declare new node control.
Class NodeTextBoxEx
    Inherits NodeTextBox
    Protected Overrides Function IsVisibleForNode(pNode As Node) As Integer
        ' display this node control only for nodes with children.
        If pNode.HasChildren Then
            Return 1
        End If
        Return -1
    End Function
End Class

' use our node control.
Dim tb As New NodeTextBoxEx()
tb.AttachTo(tree)

Note that in this case you can't add this node control through the Visual Studio designer, you need to add manually in the code.


Which method to use?

So which method do you use to control the node control visibility?
Follow these rules:

 

 


Copyright © 2006-2016 ARMSoft

www.FlexibleTreeView.com