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

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

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 PopulateTreeView(ByVal inParentID As Integer, ByRef inTreeNode As TreeNode)
objConn.Open()
myReader = objCmd.ExecuteReader

' Dim Reader As OleDb.OleDbDataReader = objCmd.ExecuteReader()
While myReader.Read
For Columns = 0 To myReader.FieldCount - 1
Category = myReader.Item(Columns)
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).Nodes.Add(Childnode). ToString()
Else
TreeView1.Nodes.Add(Parentnode).Nodes.Add(Childnod e).ToString()
'TreeView1.Nodes.Add(Childnode).Nodes.Add(Childnod e).ToString()
LastNodeSet = Parentnode
NodeRootRow += 1
End If
End If
Parentnode = Nothing : Childnode = Nothing
End While

myReader.Close()
objConn.Close()

End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
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 4239
vanc
211 Expert 100+
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
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 Expert 1GB
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
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(Selectnode)
Oct 18 '07 #5
Shashi Sadasivan
1,435 Expert 1GB
Please have a look at this wiki

You havent tried examples....looks very obvious!
Oct 18 '07 #6
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(Selectnode)

Public Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles

TreeView1.AfterSelect
Dim pnode = "Client"
Dim Selectnode = e.Node.Text
If e.Node.Text <> pnode Then
CLIENTABLE2TableAdapter.Fill(Me.AHSCLIENT2DataSet. CLIENTABLE2, 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()
InitializeComponent()
param = newparameter
End Sub


Public Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) 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
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...
1
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...
3
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...
2
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...
7
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...
3
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()...
16
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....
0
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...
3
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
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...

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.