garethh86
asked on
Large Treeview navigation menu
Hi all
I'm developing an app which contains a large amount of data input screens, I've split these up into seperate forms which are then added as controls to a panel in the main form.
I've decided to use a TreeView control as a navigation menu to get to these different input forms. The only problem is the code needed to find out which treeview item was clicked and then display the form is quite bulky, for example:
If e.Action = TreeViewAction.ByMouse Then
If e.Node.FullPath = "Customers\Add Customer" Then
Dim AddCustCtrl As New AddCustomer
AddCustCtrl.TopLevel = False
AddCustCtrl.Dock = DockStyle.Fill
MainPanel.Controls.Add(Add CustCtrl)
AddCustCtrl.Show()
End If
End If
Whats the best way of cutting down this code - can you give me an example of a function that would allow this to be done more simply. If not then am I best putting all of this inside a dll so it is seperated and makes the code on the main form more managable? Or is there an entirely different way of doing this that is easier?
The treeview has over 60 different items.
Thanks!
I'm developing an app which contains a large amount of data input screens, I've split these up into seperate forms which are then added as controls to a panel in the main form.
I've decided to use a TreeView control as a navigation menu to get to these different input forms. The only problem is the code needed to find out which treeview item was clicked and then display the form is quite bulky, for example:
If e.Action = TreeViewAction.ByMouse Then
If e.Node.FullPath = "Customers\Add Customer" Then
Dim AddCustCtrl As New AddCustomer
AddCustCtrl.TopLevel = False
AddCustCtrl.Dock = DockStyle.Fill
MainPanel.Controls.Add(Add
AddCustCtrl.Show()
End If
End If
Whats the best way of cutting down this code - can you give me an example of a function that would allow this to be done more simply. If not then am I best putting all of this inside a dll so it is seperated and makes the code on the main form more managable? Or is there an entirely different way of doing this that is easier?
The treeview has over 60 different items.
Thanks!
I have a couple of ideas, but they depend on how you're originally populating the TreeView. If you could give me some idea how the TreeView is initially being populated I can see if either of my ideas would work in your case.
ASKER
The treeview nodes are manually added, there will be no dynamic data added at runtime, its intirely static.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey I'm getting two errors with this:
Error 1 Value of type 'System.Runtime.Remoting.O bjectHandl e' cannot be converted to 'System.EventHandler'.
and
Error 2 'Unwrap' is not a member of 'System.EventHandler'.
Any ideas?
Thanks
Error 1 Value of type 'System.Runtime.Remoting.O
and
Error 2 'Unwrap' is not a member of 'System.EventHandler'.
Any ideas?
Thanks
Sounds like you declared
Dim handle as EventHandler
instead of
Dim handle as ObjectHandle
Dim handle as EventHandler
instead of
Dim handle as ObjectHandle
ASKER
Argh, sorry, selected the wrong item in autocomplete. I'm getting this error at run time when clicking a node:
Object reference not set to an instance of an object.
on
Dim handle As Runtime.Remoting.ObjectHan dle = _
Activator.CreateInstance(R eflection. Assembly.G etExecutin gAssembly( ).FullName , e.Node.Tag.ToString())
I've renamed the form to be the same as the node name, is this right?
Thanks for your help!
Object reference not set to an instance of an object.
on
Dim handle As Runtime.Remoting.ObjectHan
Activator.CreateInstance(R
I've renamed the form to be the same as the node name, is this right?
Thanks for your help!
ASKER
Sorry, being stupid, the node didn't have a tag - now that i've added that Im getting the error:
Could not load type 'AddCustomer' from assembly 'SMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
I've tried importing AddCustomer on the form but produces same error.
Could not load type 'AddCustomer' from assembly 'SMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
I've tried importing AddCustomer on the form but produces same error.
I made some assumptions, and gave one caveat, in my original post:
1. I assumed the forms you are instantiating are in the same assembly as the code for the TreeView. If that is not the case then you'll have to change Assembly.GetExecutingAssem bly().Full Name to be the name of the assembly containing the form.
2. From my original post: "The class name must be fully qualified (i.e. include the namespace)." I don't know what your namespace is for the form, but assuming it is in the same assembly as the TreeView code, and assuming the namespace matches the assembly name, you should use "SMS.AddCustomer"
1. I assumed the forms you are instantiating are in the same assembly as the code for the TreeView. If that is not the case then you'll have to change Assembly.GetExecutingAssem
2. From my original post: "The class name must be fully qualified (i.e. include the namespace)." I don't know what your namespace is for the form, but assuming it is in the same assembly as the TreeView code, and assuming the namespace matches the assembly name, you should use "SMS.AddCustomer"
ASKER
Hi
They are both in the same assembly, I have tried imports SMS.AddCust but this makes no difference.
I've tried this in a new project with two forms, treeview and a panel - I still get the same error.
Thanks
They are both in the same assembly, I have tried imports SMS.AddCust but this makes no difference.
I've tried this in a new project with two forms, treeview and a panel - I still get the same error.
Thanks
ASKER
Got it this way:
Dim newform = e.Node.Tag
Dim AddForm As Form = CType(Reflection.[Assembly ].GetEntry Assembly.C reateInsta nce( _
My.Application.Info.Assemb lyName & "." & newform), Form)
Thanks for putting me on the correct track though, this has cut several hundred lines of code own to 5 or 6 and alows me to manage what happens more.
Dim newform = e.Node.Tag
Dim AddForm As Form = CType(Reflection.[Assembly
My.Application.Info.Assemb
Thanks for putting me on the correct track though, this has cut several hundred lines of code own to 5 or 6 and alows me to manage what happens more.