473,769 Members | 1,748 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 2761
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
11556
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
969
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
1465
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
1148
by: ashokkumarsep02 | last post by:
hi , i have to create a static treeview in asp
6
3578
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
9589
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
9423
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
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.