Public Static TreeView - 08-03-2005 , 10:51 AM
Visual Studio 2003 .NET / C#
I have a treeview object on a form which acts as the main menu controller
for my application. the treeview is always in sight, and the form it is on
acts as the main container for the whole application. All other screens are
UserControls, which get added and removed from/to the main form, when the
user clicks an item on the tree view.
I thought the best way to handle navigating around would be to define the
treeview as public static, and I have a method in the main form called
ChangeScreen which is also public static. Then from any object in my project
I can just say MainMenu.ChangeScreen("Add Job"), and this will then change
the screen to the Add Job screen, and change the selected Node etc in my tree
The problem is, every so often visual studio seems to just change the
definition of my treeview to just public, instead of public static. Then of
course i get build errors because I am referencing a non static object in my
static method (ChangeScreen). Anyone now why this? Or a better way of
making this Menu change function global?
Re: Public Static TreeView - 08-04-2005 , 03:59 AM
So how do I communicate with the tree view from within one of the child
forms(User Controls in my case) that sit in the main form? The user can
navigate to other menu options from within child forms, so I need a way of
firing off a menu item from within a child object.
"Frans Bouma [C# MVP]" wrote:
Re: Public Static TreeView - 08-04-2005 , 06:22 AM
Think I have a solution:
I have a Form called MainForm. On this form is just a TreeView. MainForm
has a public method called ChangePage which recieves a string.
The TreeView has a structure like this:
I have 3 User Controls, SubForm1, SubForm2, SubForm1a. When I click on the
Sub1a treeview item, it creates an instance of SubForm1, and adds it to the
Controls collection of my MainForm. SubForm1a is a member of SubForm1's
SubForm1 has a button to change page to SubForm2. When the user clicks this
button it does this:
this then calls the changePage method in my MainForm which in turn, removes
SubForm1 from the Controls collection, and adds SubForm2 instead.
Likewise SubForm1a, which is within SubForm1, has a button to do the same
thing, to do this my code says:
This seems to work fine for me.
|Thread Tools||Search this Thread|