![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Steve wrote: 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 view. 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? Your treeview is an INSTANCE referenced by a form object, so it's not preferable to have that static. (no use also, it's local to the form). If you want to communicate with the treeview, do that through the form, that's proper OO encapsulation. I have a similar setup, I have a form with a treeview with a complete project graph, and when someone selects something in a context menu on a node, the code fires events which are handled by the mainform (handled as in: re-routed to the proper code to handle/do the action). As, after all, it's no different from MDI programming where the mainform is the controller of the application and all actual forms are childs inside that form, communicating with eachother and the rest of the app THROUGH the mainform. Frans -- ------------------------------------------------------------------------ Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com My .NET blog: http://weblogs.asp.net/fbouma Microsoft MVP (C#) ------------------------------------------------------------------------ |
#3
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |