473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Public Static TreeView


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?

Thanks Steve
Aug 3 '05 #1
3 2717
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#)
------------------------------------------------------------------------
Aug 4 '05 #2

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.

Thanks

Steve

"Frans Bouma [C# MVP]" wrote:
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#)
------------------------------------------------------------------------

Aug 4 '05 #3
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:

-Main1
- Sub1a
-Main2
- Sub2a

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
controls.

SubForm1 has a button to change page to SubForm2. When the user clicks this
button it does this:

((MainForm)this.Parent).ChangePage("Sub2a");

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:

((MainForm)this.Parent.Parent).ChangePage("Sub2a") ;

This seems to work fine for me.

Thanks

Steve
Aug 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
0
by: john bailo | last post by:
I am attempting to create a c# program to iterate through the messages in an Outlook/Exchange public folder and extract the headers. My apologies to the VB/VBA groups, but you seem to have more...
4
by: Peter Speybrouck | last post by:
I have a little problem with a webservice. I reproduced the problem in the following simplified example. I just create a new C# ASP.NET webservice and a c# console application. I added a new...
0
by: meh | last post by:
Everytime I think I understand this it bites me....... I have a derived tree control on a MDI parent form. From a child form I want to be able to add a node (or modify). The tree (CurrTree) has...
3
by: Steve | last post by:
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...
3
by: urs.eichmann | last post by:
Hello, several parts of the pages of my ASP.NET 2.0 site are mainly static, such as a treeview with all the product categories, a menu bar, the company header and so on. But they also have a...
2
by: MrNobody | last post by:
I am trying to extend TreeView to add some of my own functionality and I needed to put a public method but the compiler won't let me and I really don't understand why. I declared my class: ...
0
by: ashokkumarsep02 | last post by:
hi , i have to create a static treeview in asp
6
by: stoogots2 | last post by:
am using Visual Studio 2003, .Net Framework 1.1, C#. I get a SystemNullReferenceException when trying to do a hashtable.add(string,string) from a login page, and I do not understand why because all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.