473,403 Members | 2,354 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,403 software developers and data experts.

Calling forms dynamically

Mac
Hi all,

I have a treeview in a MDI container form which is going to act as a menu for
my windows application. When someone clicks on a node in the treeview it will
open a new form.

I know I could write an exhaustive case statement that handled each node
individually but I would to do this with as minimal code as possible. The
first thing I was going to do was create a custom treeview control and add a
property for the form name. Therefore when I click on a node I will have the
form I want to open.

But I need to create an instance of this form before I show it. So is it
possible to do this dynamically such that I could use the same chunk code to
instaniate all possible forms that are in the treeview and then show them?

regards,

Mac
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200507/1
Nov 21 '05 #1
4 1262
Mac,

Can you have a look if this sample on our site does help you?

http://www.windowsformsdatagridhelp....e-1401ee5860d3

I hope this helps,

Cor
Nov 21 '05 #2
see http://www.utmag.com/September2003/Page11.asp

--
HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)

"Mac" <fo***@DotNetMonster.com> wrote in message
news:50***********@DotNetMonster.com...
Hi all,

I have a treeview in a MDI container form which is going to act as a menu
for
my windows application. When someone clicks on a node in the treeview it
will
open a new form.

I know I could write an exhaustive case statement that handled each node
individually but I would to do this with as minimal code as possible. The
first thing I was going to do was create a custom treeview control and add
a
property for the form name. Therefore when I click on a node I will have
the
form I want to open.

But I need to create an instance of this form before I show it. So is it
possible to do this dynamically such that I could use the same chunk code
to
instaniate all possible forms that are in the treeview and then show them?

regards,

Mac
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200507/1

Nov 21 '05 #3
"Mac" <fo***@DotNetMonster.com> schrieb:
I have a treeview in a MDI container form which is going to act as a menu
for
my windows application. When someone clicks on a node in the treeview it
will
open a new form.

I know I could write an exhaustive case statement that handled each node
individually but I would to do this with as minimal code as possible. The
first thing I was going to do was create a custom treeview control and add
a
property for the form name. Therefore when I click on a node I will have
the
form I want to open.

But I need to create an instance of this form before I show it. So is it
possible to do this dynamically such that I could use the same chunk code
to
instaniate all possible forms that are in the treeview and then show them?


Instantiate the forms and assign them to the treenodes' 'Tag' properties.
Later you can show the form as shown below:

\\\
DirectCast(Me.TreeView1.SelectedNode.Tag, Form).Show()
///

Alternatively you can create the form instances by need, which is
preferrable when dealing with lots of forms. To do that, assign the form
types to the treenodes' 'Tag' properties:

\\\
Dim tn As New TreeNode()
....
tn.Tag = GetType(FooForm)
....
///

Creating a form using a type object:

\\\
Imports System.Reflection
..
..
..
Dim frm As Form = _
DirectCast( _
Activator.CreateInstance( _
DirectCast(Me.TreeView1.SelectedNode.Tag, Type) _
), _
Form _
)
frm.Show()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Thanks to Cor, Eric & Herfried for postings on this issue - you have given me
plenty to look into.

regards,

Mac
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200507/1
Nov 21 '05 #5

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

Similar topics

6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
0
by: Michael Brandt Lassen | last post by:
Hi gurus This problem is about calling Web services secured by Forms Authentication from Windows Forms user controls embedded in HTML. Using the object tag I’ve managed to include a Windows...
4
by: Jerry Krinock | last post by:
I've written the following demo to help me understand a problem I'm having in a larger program. The "main" function constructs a Foo object, and then later "reconstructs" it by calling the...
6
by: JonS. | last post by:
Hi, I'm trying to create a Windows Forms portal application and need some help. What I currently have is a main application (.exe) containing an MDI form. The idea is that this main application...
12
by: Peter Van Wilrijk | last post by:
Hi, In VB6 I have the following code ... Dim frmLink As Form Set frmLink = Forms.Add(stringformname) frmLink.Show 'wait until all data has been loaded Do Until frmLink.Loaded = 21 DoEvent
7
by: WhiskRomeo | last post by:
I have a WIN .NET application that calls a web service to retrieve data. I deployed the application to a server and configured the webservice. The webservice and SQL Server 2000 database are on...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
0
by: anishanc | last post by:
Hai dear I have a sales form that contains a button to create new item, when the item's form is displayed i just disable the sales form. My question is that how can i enable the sales form...
4
by: varunbhatia87 | last post by:
I am developing an application in vb.net, in which i m using a treeview control which display nodes generated from database, when i select a node it gives me a form name that comes also from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
0
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...

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.