473,756 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Change Screen("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 2759
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.Change Screen("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.Change Screen("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).Change Page("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("Su b2a");

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
11549
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
2650
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 information for Office automation than the c# groups. I am having some problems manipulating the various object models. I say various because based on what source code I could find, I am trying to use the Outlook, CDO and MAPI type libraries
4
2420
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 class test to the namespace of the webservice which I try to access from the console application. //Service1.asmx.cs
0
966
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 Public WithEvents CurrTree As TreeView defined in the parent (MDI) and the same tree(CurrTree) is also defined in a module as a Public CurrTree As TreeView
3
267
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 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...
3
1341
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 dynamic part, such as a product list. If I look at the rendered HTML, the static parts are roughly 60%-70% of the whole HTML sent to the client. Especially the treeview will quickly sum up to 30K of nested TABLE, TR, TD tags and javascript. Since...
2
1464
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: public class MyTree : TreeView and then tried to add a simple method:
0
1147
by: ashokkumarsep02 | last post by:
hi , i have to create a static treeview in asp
6
3577
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 of the other data items from the Global.asax.cs are accessible in my pages. The key and value are not null (according to the watch window), so it is something else. This is likely something retarded, so I apologize in advance. It is my first...
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9886
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9722
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.