Introduction
TreeView in C# is a great control. TreeView can be used to build Hierarchical Menus. I was involved in a project where i had to make use of TreeView quite heavily and as a result i wrote some code myself to Build the TreeView dynamically (database driven). Here i present the TreeView traversal operation.
Here's a snapshot of the Populated TreeView.
Download sourcecode
Here is the code:
class</FONT> TVIEW
<P>
<FONT color=#008000 size=1></P><P>
</FONT><FONT size=1></P><P></FONT><FONT color=#008000 size=1></FONT> </P><P><FONT color=#008000 size=1>
</P></FONT><P><FONT color=#008000 size=1>
</P>
private void TraverseTreeView(TreeView tview)<BR>
{
TreeNode temp = new TreeNode();
for(int k=0; k<tview.Nodes.Count; k++)
{
temp = tview.Nodes[k];
MessageBox.Show(temp.Text);
for (int i = 0; i < temp.Nodes.Count; i++)
visitChildNodes(temp.Nodes[i]);
}
</P>
<P><FONT color=#0000ff size=1>private</FONT><FONT size=1> </FONT><FONT color=#0000ff size=1>void</FONT><FONT size=1> visitChildNodes(TreeNode node)</FONT></P><PRE lang=cs>
{
//Display the Text of the node
MessageBox.Show(node.Text);
//Loop Through this node and its childs recursively
for (int j = 0; j < node.Nodes.Count; j++)
visitChildNodes(node.Nodes[j]);
}
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.