ExtendedTreeViewItem Property

This can be used to get a tree node by name from the tree view (a root node or any child at any level).

Definition

Namespace: EWSoftware.ListControls
Assembly: EWSoftware.ListControls (in EWSoftware.ListControls.dll) Version: 2023.4.9.0
public TreeNode this[
	string name
] { get; }

Parameters

name  String
The name of the tree node to retrieve.

Property Value

TreeNode
Returns the tree node that was found or null if it was not found.

Remarks

The tree's nodes are searched recursively for the first node with a name that matches the specified value. The value is case-sensitive. Note that node names do not have to be unique. Only the first node found is returned even if other nodes further down the tree have an identical name.

Example

C#
string name = txtFindName.Text.Trim();

if(name.Length == 0)
{
    MessageBox.Show("Enter a node name to find", "Tree View Demo",
        MessageBoxButtons.OK, MessageBoxIcon.Error);
    return;
}

// Simply use the indexer with the name of the node.  Note that
// node names aren't necessarily unique (they are in the demo) so
// it returns the first node found with the given name.
TreeNode node = tvExtTree[txtFindName.Text];

if(node != null)
{
    tvExtTree.SelectedNode = node;
    node.EnsureVisible();
    tvExtTree.Focus();
}
else
    MessageBox.Show("Unable to find node named '" + name + "'.  " +
        "The name is case-sensitive.  Use the tool tips or enable " +
        "the form DrawNode events to verify the node names and " +
        "try again.", "Tree View Demo", MessageBoxButtons.OK,
        MessageBoxIcon.Error);

See Also