473,770 Members | 4,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I Pass a parameter to a child form from parent form in VB.net?

6 New Member
I have a parent form that uses a Treeview Control and I would like to pass the node selected to a child form where the user will add update or delete the record selected using a dataset. Is there a way to pass the selected node as a parameter to the child form?

Here's my code thanks in advance!

Private Sub PopulateTreeVie w(ByVal inParentID As Integer, ByRef inTreeNode As TreeNode)
objConn.Open()
myReader = objCmd.ExecuteR eader

' Dim Reader As OleDb.OleDbData Reader = objCmd.ExecuteR eader()
While myReader.Read
For Columns = 0 To myReader.FieldC ount - 1
Category = myReader.Item(C olumns)
Next
On Error Resume Next
Parentnode = "AHS System Users"
Childnode = Split(Category, "")(0)
If Childnode = Nothing Then
TreeView1.Nodes .Add(Parentnode )
'LastNodeSet = Parentnode
LastNodeSet = Childnode
NodeRootRow += 1
Else
If Parentnode = LastNodeSet Then
TreeView1.Nodes (NodeRootRow).N odes.Add(Childn ode).ToString()
Else
TreeView1.Nodes .Add(Parentnode ).Nodes.Add(Chi ldnode).ToStrin g()
'TreeView1.Node s.Add(Childnode ).Nodes.Add(Chi ldnode).ToStrin g()
LastNodeSet = Parentnode
NodeRootRow += 1
End If
End If
Parentnode = Nothing : Childnode = Nothing
End While

myReader.Close( )
objConn.Close()

End Sub

Private Sub TreeView1_After Select(ByVal sender As System.Object, ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles TreeView1.After Select
Dim pnode = "AHS System Users"
Dim Selectnode = e.Node.Text
If e.Node.Text <> pnode Then
Dim F5 As New Form5()
F5.MdiParent = Me
F5.Show()
End If
Oct 16 '07 #1
6 4278
vanc
211 Recognized Expert New Member
Of course you can pass tree view node to your child form.
e.g. Child form provides method accept TreeViewNode as parameter and Parent form calls it passing the selected node. Is it what you want?
Cheers.
Oct 16 '07 #2
dav61000
6 New Member
yes thats exactly what I need to do I am new to vb.net can you show me how to do that using my code?

for example I have a parent form called form4 and I want to pass the selected node from the treeview residing on the form4 and pass this node as a parameter to the child form5.

Dim Selectnode As String
Selectnode = e.Node.Text
If e.Node.Text <> pnode Then

Dim F5 As New Form5()
F5.MdiParent = Me
F5.Show()
End If

Thanks
Oct 17 '07 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Override the constructor of Form5 to accept a parameter.
An pass the node as a parameter to Form5 using the new constructor.

If you want code about this, There will be a lot of OOP's for begineers tutorial around

Please look at that rather than getting a sloution from the forums (the tutorials will also give you a lot of conceptual knowledge )
Cheers
Oct 17 '07 #4
dav61000
6 New Member
I have looked at numerous tutorials and thought I found what I was looking for however I am having trouble understanding how to override or overload the constructor of the form to include a parameter. I am using Visual studio 2005 and when I key in examples from different tutorials such as this one I get an error.
"Too many arguments to 'Public Sub New()"

Please help me understand
thank you

for example trying to overload form6
by saying

Private otherform As new form6(Selectnod e)
Oct 18 '07 #5
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Please have a look at this wiki

You havent tried examples....loo ks very obvious!
Oct 18 '07 #6
dav61000
6 New Member
ok so maybe I should have looked at the tutorials a little closer before asking for help but now I think I am really close but I am having a problem loading the variable into the parameter to be passed. I can't seem to pass the selectnode as a variable but I am able to pass it as a string literal example
selectnode = "john" vs. selectnode = e.node.text

thanks for your help!

here's my code:

For Form1:

Public Shared Selectnode As String
Public Shared otherForm As New Form2(Selectnod e)

Public Sub TreeView1_After Select(ByVal sender As System.Object, ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles

TreeView1.After Select
Dim pnode = "Client"
Dim Selectnode = e.Node.Text
If e.Node.Text <> pnode Then
CLIENTABLE2Tabl eAdapter.Fill(M e.AHSCLIENT2Dat aSet.CLIENTABLE 2, Selectnode)
otherform.show( )
End If
End Sub

form2 code:
Public Class Form2
Inherits System.Windows. Forms.Form

' Windows Forms Designer generated code region

Public param As String

Public Sub New(ByVal newparameter As String)
MyBase.New()
InitializeCompo nent()
param = newparameter
End Sub


Public Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
MessageBox.Show (param)
End Sub
End Class
Oct 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1675
by: cksj | last post by:
I have a link on my web app that opens a pop-up window. In the pop-up window, the user can search for policy information. The result is displayed on a datagrid. The datagrid has 1 hyperlink column and 3 bound columns. When the user clicks the hyperlink, it passes the data of the hyperlink to the parent window. This part works great. However, I would like to pass the data on all 4 columns to the parent window. Do you know how I can do this?...
1
2120
by: VbUser25 | last post by:
hi.. i have a drop-down menu with a list of products.when i select any one product i open a popup displaying hte product categories in it.i then enter the no. of items i want.and finally when i click to the submit button i want to display a summary of selected item in the parent form.to make it more elaborate: i have 3 items in a drop-down menu and each item has further 10 different types of products.
3
3946
by: Omar Llanos | last post by:
I have Form1 and Form2 (which is inherited from Form1), and I created a button in Form2 that will fill up a textbox in Form1. What code would do that? I tried the simplest way: //from child form in button2 clicked event: textbox1.Text = "Hello";
2
6969
by: Chandru | last post by:
hi I want to know how to pass values from different forms. That is, i created one parent form. from there i opened child form modeless way. Once i close the child form i need some value from child form that to be transferred in Parent form. thanks in advance.
7
2600
by: mark | last post by:
I have a main form, and i have another form i need to call on a button press, then id like the result of the child form to pass data back to the parent - without losing any data previously entered on the parent - is this possible ? ( my main parent window is starting to get quite cluttered) cheers mark
3
6265
by: LEE | last post by:
I'd like to call a function of child from parent form, there is an issue: Form1 (parent) calls "LoadMe" Sub in Form2 (child), it works using the codes (in Form1): Dim frm As New Form3() frm.LoadMe() but fails using these codes: Dim frm As Form ' defined as a global variable
16
1657
by: John | last post by:
Hi I have posted this question several times but have received no reply. I have a main form which contains a panel which in turn contains a child form, like this; MainForm->MyPanel->ChildForm. The question is; how can I, from the child form, get a reference to the main form? If I try to do dim frm as new mainform then I get reference to a second instance of the mainform which is not the same as the original instance of the mainform. ...
0
355
by: mabond | last post by:
Firstly I hope I'm in the right forum ..... if not can someone re-direct me please. I have an application with a main form properties set to mdiparent = true. Toolbar button allows user to open an instance of Excel for work on a particular file dim xlApp as New Excel.Application xlApp.Visible = true
3
1728
by: Vivek | last post by:
Hi, I wish to refresh the parent form and pass the new values from child form. How can I do it? Thanks
0
9595
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
9432
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
10059
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...
1
10008
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
9873
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
7420
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
5313
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
3974
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
3
2822
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.