Visibility inside the node
Flexible TreeView has these ways to control the node control visibility inside a node:
- Visible node control property.
- Node control filtration node control property.
- Visibility and VisibilityManager node control properties.
- IsVisibleForNode node control method.
Which method to use?
Here is the quick guide to choose which method to use to control the node control visibility:
Visible property#
You can control the node control's visibility using the Visible property (enabled by default).
Note
If the node control is not visible (Visible=false), all other visibility settings are 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 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:
- Disabled - shows all node controls within every node.
- Static - filter's settings are stored in the NodeControlFilter treeview property.
- Dynamic - filter's settings are dynamically requested each time through the FilterNodeControl treeview event.
- UseVisibility - the node control visibility is controlled by its Visibility property value. Use this mode to change the node control visibility based on different node states, like selected, focused, etc.
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 node controls.
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:
- Visible - node control is always visible within the specified node.
- Hidden - node control is always hidden within the specified node.
- VisibleForThisNodeOnly - node control is visible only within the specified node.
Note that you can apply this mode for many nodes and the node control will be visible only for all those nodes!
Example
// 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 your 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 decide whether to show a specified node control inside a specified node.
Note
If you don't change the ControlVisibility property in the FilterNodeControl event, the node control will be visible within every 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 treeview, FilterNodeControlEventArgs args)
{
// hide the image node control in the child node.
if (args.Node.Text == "Child node" && args.NodeControl is NodeImage)
{
args.ControlVisibility = eNodeControlVisibility.Hidden;
}
}
' 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.
AddHandler tree.FilterNodeControl, AddressOf tree_FilterNodeControl
Private Sub tree_FilterNodeControl(treeview As FlexibleTreeView, args As FilterNodeControlEventArgs)
' hide the image node control in the child node.
If args.Node.Text = "Child node" AndAlso TypeOf args.NodeControl Is NodeImage Then
args.ControlVisibility = eNodeControlVisibility.Hidden
End If
End Sub
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
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 the node 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.
Note
You can use the UseVisibility filtration mode to do the same but Visibility and VisibilityManager properties provide more centralized way to control the node control visibility.
The Visibility property allows you to define a node's states for every node control separately.
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 tb2 = new NodeTextBox();
// show this node control only for the selected or under the mouse cursor node.
tb2.Visibility = eObjectVisibility.SelectedNode | eObjectVisibility.HotNode;
tb2.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 tb2 As New NodeTextBox()
' show this node control only for the selected or under the mouse cursor node.
tb2.Visibility = eObjectVisibility.SelectedNode Or eObjectVisibility.HotNode
tb2.AttachTo(tree)
The VisibilityManager allows you to control visibility of many node controls from one point.
// 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;
// temporarily 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
' temporarily 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.
Note
To tell the treeview to use this method, you need to enable the node control filtration (either the static or dynamic mode, but static mode is more performant) using the NodeControlFilterMode treeview property.
You should return one of these values from the IsVisibleForNode method:
false
- the node control is not visible in the specified node.true
- the node control is visible in the specified node.ARMSoft.FlexibleTreeView.Boolean.Undefined
- do not use this method's result and evaluate other settings.
Note
The result of this method has priority over all other settings if it returns false
or true
values.
Although the IsVisibleForNode
method returns a ARMSoft.FlexibleTreeView.Boolean.Undefined
type, you can explicitly return true
or false
values. However, for the undefined
value, you need to return ARMSoft.FlexibleTreeView.Boolean.Undefined
.
To manually control the node control visibility, derive a new node control class from the built-in one and override its IsVisibleForNode method:
// declare new node control.
class NodeTextBoxEx : NodeTextBox
{
protected override ARMSoft.FlexibleTreeView.Boolean IsVisibleForNode(Node node)
{
// display this node control only for nodes with children.
if (node.HasChildren)
{
return true;
}
return ARMSoft.FlexibleTreeView.Boolean.Undefined;
}
}
// use our node control.
NodeTextBoxEx tb = new NodeTextBoxEx();
tb.AttachTo(tree);
' declare new node control.
Class NodeTextBoxEx
Inherits NodeTextBox
Protected Overrides Function IsVisibleForNode(node As Node) As ARMSoft.FlexibleTreeView.Boolean
' display this node control only for nodes with children.
If node.HasChildren Then
Return True
End If
Return ARMSoft.FlexibleTreeView.Boolean.Undefined
End Function
End Class
' use our node control.
Dim tb As New NodeTextBoxEx()
tb.AttachTo(tree)
In this case, you can't add the NodeTextBoxEx
node control through the Visual Studio designer because it's a custom node control type; you need to add it manually in the code.
Which method to use?#
So which method to use to control the node control visibility?
Follow these rules:
- If you want just hide the node control no matter what other visibility settings you have, just disable its Visible property.
- If you already know for which nodes the node control will be visible or invisible and don't have many nodes, use the static filtration mode. Don't use it when you need to change the node control visibility for many nodes as it may hurt performance.
- If you don't know for which nodes the node control will be visible, or if you want to dynamically decide the node control visibility without much additional coding, use the dynamic filtration mode.
- If the node control visibility depends on the node's state, use the Visibility or VisibilityManager node control properties.
- If you have complex rules of node control visibility or want to control it manually, use the IsVisibleForNode node control method. This way is optimal for a treeview with many nodes and is very fast.