dynamically remove TreeNodes
This one is giving me a real headache for the last couple of days.
I'm wriing a TreeView and this is how it should work. Tree view has set of nodes and each node contains set of other nodes as well.
Based on the logged in users access rights I want to remove some nodes.
I'm getting access rights as a string from the DB and looks like this
frmAdminRegisterWindow,Admin,1,;frmAdminUser,Admin,1,;Admin,,0,;
<NodeName>,<ParentNodeName>,<Visible>
Here is the deal
I want to remove the treeNodes and I tried this code
if (readOnly == "0")
{
treeView1.Nodes[nodeName].Remove();
}
which gives an exception to me stating that "Object reference not set to an instance of an object."
This is the code segment I have above that if statement to add the Nodes
treeView1.Nodes.Clear();
//NOTE: Node name has to be applicatin wide unique name
//User Administration
TreeNode Admin = treeView1.Nodes.Add("Admin");
Admin.Nodes.Add("frmAdminUser", "User");
Admin.Nodes.Add("frmAdminRegisterWindow", "Register Window");
So if the nodeName = Admin it should remove the TreeNode Admin, but instead I'm getting the above exception.
Any idea?