Visual Basic .NET » Windows Forms
Help with windowsform.treeview control .NET 1.1 -- rhaazy --


I am working with a treeview control that navigates a database. The depth of the tree is totally dynamic in the sense that it starts by displaying the organizational structure of the business using the software. To explain this my root nodes are NorthAmerican, Canada,
Europe, and Australia (this is for my example, there could be any number of these "system" nodes). After clicking a "system" node it expands into whatever other regions are assigned to the system. For example North American could expand into various states. These nodes are refered to as "System Children". From there any node that is part of the organizational structure is referred to as any "node". Along with these organizational nodes two other nodes that are placed with the expansion of each node, a "assets" and "employees" node are available under any level of the treeview. Depending on what level of the tree decides what assets or employees are displayed. So if someone clicked on the assets or employees node that appears after the root system nodes then ALL assets and employees are displayed. And it gets more specific as you go farhter down the tree... After assets are expanded it shows all the asset names, then you click an asset name to display a list of Scan results, click on one of those to get a particular attribute, etc etc...

My problem is that I am starting to have a hard time determining where in the tree and what functions should be called using my various if statements. I am stuck right now using methods that check to see if the text of the node = "asset" or if the parent of the selected node =
"asset" and im using a treelevel function to find out exactly what the
"level" or "depth" of the tree I'm at and its getting rather rediculous...heres an example of what I mean.
if (treelevel > 0 && treeView1.SelectedNode.ToString().Trim().Remove(0,
10) != "Assets" &&
treeView1.SelectedNode.Parent.ToString().Trim().Remove(0, 10) !=
"Assets" && treeView1.SelectedNode.ToString().Trim().Remove(0, 10)
!= "Employees" &&
treeView1.SelectedNode.Parent.ToString().Trim().Remove(0, 10) !=
"Employees" &&
treeView1.SelectedNode.Parent.ToString().Trim().Remove(0, 10) != "Show All Assets")

And each time I have to add more stuff things like this are getting worse and worse....

I want to know if there is a better method to determining what exactly should be happening when a particular node is clicked... The organization strucutre part of it is verys imple as this is stored in a relational database using tables to designate nodeIDs and nodeParentIDs... I am desperate to find a new approach to my problem...If anyone can make any sense of what I'm talking about I would be most appreciative for some help.

If there is still some difficulty understanding what it is I'm dealing with I would be more than happy to sit down for an hour and throw together some detailed explanations with pictures and what not....

Thanks in advance.

[Submit Comment]Home