HomeActive Query Builder - HowTos and TroubleshootingHow-tos for WinForms .NET EditionHow to expand specific node of the Database Schema Tree?

2.4. How to expand specific node of the Database Schema Tree?

First, please note that there's a way to automatically expand all nodes of the tree for certain number of levels. This is determined by the QueryBuilder.DatabaseSchemaTreeOptions.DefaultExpandLevel property.

To expand specific namespace node, use the following code sample.

{ 
	ICustomTreeView databaseSchemaTree = queryBuilder1.DatabaseSchemaTree;
	FindAndExpandSchemaNode(databaseSchemaTree.RootNode, "HumanResources");
}

private void FindAndExpandSchemaNode(object parentTreeNode, string name)
{
	ICustomTreeView databaseSchemaTree = queryBuilder1.DatabaseSchemaTree;

	object child = databaseSchemaTree.GetNodeFirstChild(parentTreeNode);
	while (child != null)
	{
		var metadataStructureItem = databaseSchemaTree.GetNodeTag(child) as MetadataStructureItem;
		var metadataItem = metadataStructureItem.MetadataItem;
		if ((metadataItem.Type & MetadataType.Namespaces) > 0)
		{
			if (metadataItem.Type == MetadataType.Schema)
			{
				if (metadataItem.Name == name)
				{
					databaseSchemaTree.SetNodeExpanded(child, true);
					return;
				}
			}
			else
			{
				databaseSchemaTree.SetNodeExpanded(child, true);
				FindAndExpandSchemaNode(child, name);
			}
		}

		child = databaseSchemaTree.GetNodeNextSibling(child);
	}
}

This page was: Helpful | Not Helpful