Link to home
Start Free TrialLog in
Avatar of garethh86
garethh86Flag for United Kingdom of Great Britain and Northern Ireland

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(AddCustCtrl)
                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!
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

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.
Avatar of garethh86

ASKER

The treeview nodes are manually added, there will be no dynamic data added at runtime, its intirely static.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey I'm getting two errors with this:

Error      1      Value of type 'System.Runtime.Remoting.ObjectHandle' cannot be converted to 'System.EventHandler'.

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
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.ObjectHandle = _
           Activator.CreateInstance(Reflection.Assembly.GetExecutingAssembly().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!
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.
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.GetExecutingAssembly().FullName 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"
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
Got it this way:

Dim newform = e.Node.Tag

            Dim AddForm As Form = CType(Reflection.[Assembly].GetEntryAssembly.CreateInstance( _
            My.Application.Info.AssemblyName & "." & 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.