473,378 Members | 1,395 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,378 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 2714
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?

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.