|
-
Jun 3rd, 2009, 07:26 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] How to pass value from Independent form to child form
Please help how could i pass the value from Independent form to a child form..
in my declaration from MDIParent form i declared child form as frmSMRP then in the frmSMRP i have declare one new form as form1
here is my code below.
declaring child form under MDIParent form
Code:
Dim FrmSMRPOffline As New FrmSMRPOffline
FrmSMRP = New FrmSMRPOffline
FrmSMRP.MdiParent = Me
FrmSMRP.Show()
FrmSMRP.WindowState = FormWindowState.Maximized
Declaring independent form under child form
Code:
Dim form1 As New FrmHistorydetails
form1.Owner = mdiTSMobile
form1.ShowDialog(Me)
i have tried passing the value under independent form but did not work
Code:
frmSMRP.myID.text = form1.myID.text
now, how could i pass the value from independent form into child form?
please help..
-
Jun 4th, 2009, 12:33 AM
#2
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
anybody know this issue please help?
-
Jun 4th, 2009, 02:07 AM
#3
Re: How to pass value from Independent form to child form
The way I would do it is rather than use form1.showdialog I would create a public function in frmHistoryDetails which would return the value you want, ie
Code:
Class FrmHistoryDetails
Private ReturnVal as String
Public Function Start() as String
Me.ShowDialog
Start = ReturnVal
End Function
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.click
ReturnVal = myId.Text
End Sub
End Class
Assuming that your OK button has its dialogresult set (otherwise just add me.close after the line setting the returnval). Then in your calling code :
Code:
Dim form1 As New FrmHistorydetails
form1.Owner = mdiTSMobile
myID.text = form1.Start()
-
Jun 4th, 2009, 02:42 AM
#4
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
Where should i put this code?
Code:
Dim form1 As New FrmHistorydetails
form1.Owner = mdiTSMobile
myID.text = form1.Start()
-
Jun 4th, 2009, 02:44 AM
#5
Re: How to pass value from Independent form to child form
Wherever you like.
It is a direct replacement for your original block (the 2nd in your example) which is almost identical, so I'd suggest putting it exactly where your current code is.
-
Jun 4th, 2009, 03:45 AM
#6
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
thanks for responce Keystone but sadly it did not work.. here i want to explain it more clear..
i have to transaction from specefic customer for example the image below..
based on the status i'm done bringing the item information from SMRPoffline (as child form) into frmhistory, now based on the transaction history of the customer i want to select the price based on it's history transaction. then how could i put it back the Price of the item from history into child form again without closing both form.
see the image below i have selected the price,
now what i want is "When i press the select price button from frmhistorydetails(Sales History details) the value of the price will be pass into the Price textback of the child form, this box beside the Red label with "History Price", in short i want to replace the 155628.66 with 40676.89 on the spot without closing both form.. please help
Last edited by edgarbenilde; Feb 8th, 2010 at 08:29 AM.
-
Jun 4th, 2009, 04:01 AM
#7
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
then, i need bring also some data from Child form into the frmhistorydetails i can't use the code below because if i used it it will not display those items.. thanks in advance hope this will be solve
Code:
Dim form1 As New FrmHistorydetails
form1.Owner = mdiTSMobile
myID.text = form1.Start()
-
Jun 4th, 2009, 04:06 AM
#8
Re: How to pass value from Independent form to child form
OK - your problem then is in using ShowDialog - that means processing of your calling form is suspended until the user closes the new dialog.
You could amend the Start procedure to accept a reference to the control you want to update, and then within your new form when the relevant item changes then you can set the target control's value there, ie
Code:
Public Class FrmHistoryDetails
Private BoxToUpdate as TextBox
Public Sub Start(byref myTextBox as TextBox)
BoxToUpdate = myTextBox
Me.ShowDialog
End Function
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.click
BoxToUpdate.Text = myID.text
End Sub
End Class
Edit - just seen your latest post - you can pass in whatever information you want by adding extra argumens to the Start procedure and passing the the values through.
Last edited by keystone_paul; Jun 4th, 2009 at 04:44 AM.
-
Jun 4th, 2009, 04:15 AM
#9
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
there is an error line (Blue line) in the me.showDialog is say's" it not a member..
-
Jun 4th, 2009, 04:25 AM
#10
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
boxtoupdate means the box in the child? it did not work
-
Jun 4th, 2009, 04:29 AM
#11
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
by the way this is Visual studio 2005
-
Jun 4th, 2009, 04:41 AM
#12
Re: How to pass value from Independent form to child form
So long as the class is a form, showdialog should work fine.
When you say "boxtoupdate means the box in the child? it did not work " what do you mean
BoxToUpdate should be the control on the calling form which you wish to update.
Are you saying it won't update?
EDIT - sorry, cut and paste error. In the btnOK_click function that should be BtnToUpdate.text = myID.text. I've amended the code above to correct it.
Last edited by keystone_paul; Jun 4th, 2009 at 04:44 AM.
-
Jun 4th, 2009, 05:08 AM
#13
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
yes i did not update then i can't run because there is an erorr in me.showdialog it say's "Ot's not a member of the form frmhistorydetails
-
Jun 4th, 2009, 05:14 AM
#14
Re: How to pass value from Independent form to child form
Can you post the exact code you have?
-
Jun 4th, 2009, 05:55 AM
#15
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
this is my code here
Code:
Private BoxToUpdate As TextBox
Public Sub Start(ByRef txtprice As TextBox)
BoxToUpdate = txtprice
Me.ShowDialog()
End Sub
Private Sub btnSeletecPrice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeletecPrice.Click
txtPrice.Text = Me.BoxToUpdate.Text
End Sub
-
Jun 4th, 2009, 05:59 AM
#16
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
may be because this is not assigned
Code:
Private BoxToUpdate As TextBox
-
Jun 4th, 2009, 06:00 AM
#17
Re: How to pass value from Independent form to child form
Yes but where is that code? It should be within a form class. Is it?
If it is not within a form then ShowDialog will not work, if it is within a form it will.
BoxToUpdate is declared as a module-level variable, and its contents are assigned in the Start mehod.
-
Jun 4th, 2009, 06:07 AM
#18
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
yah i did this is the entire code, those in bold are your code that part only didnot work when i pass the value from this for into the child form..
that is the entire code i have and the textbox name of textbox in the child form is txtPassprice.text that is where i want to pass the value of the txtprice.text textbox
Code:
Public Class FrmHistorydetails
Public HitemCode, Hcuscode As String
Private Sub FrmHistorydetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Me.txtCustCode.Text = Me.Hcuscode
' Me.txtItemCode.Text = Me.HitemCode
' MessageBox.Show(Hcuscode)
' MessageBox.Show(HitemCode)
' Me.txtItemCode.Text = FrmSMRP.MatNoComboBox.Text
' Me.txtCustCode.Text = FrmSMRP.CustNoComboBox.Text
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(7).Visible = False
End Sub
Private Sub FrmHistorydetails_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Try
If Me.txtCustCode.Text <> "" Or Me.txtItemCode.Text <> "" Then
Me.SalesHistoryTableAdapter.FillByCustItem(Me.SMRPSourceDataSet.SalesHistory, Me.txtCustCode.Text, Me.txtItemCode.Text)
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(7).Visible = False
Me.SalesHistoryTableAdapter.FillByCustItem(Me.SMRPSourceDataSet.SalesHistory, Me.txtCustCode.Text, Me.txtItemCode.Text)
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(7).Visible = False
Else
End If
Catch ex As Exception
Me.Dispose()
End Try
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If Me.DataGridView1.CurrentRow IsNot Nothing Then
myrowindex = DataGridView1.CurrentRow.Index
mycellinfo = DataGridView1.Item(6, myrowindex).Value.ToString
Me.txtPrice.Text = mycellinfo
End If
Try
If txtPrice.Text <> "" Then
Dim dblTranspo As Double
dblTranspo = txtPrice.Text
txtPrice.Text = Format(dblTranspo, "#,##0.00")
Me.txtPrice.Text = Me.txtPrice.Text
End If
Catch ex As Exception
Me.txtPrice.Text = "Invalid multiplier"
Exit Sub
End Try
End Sub
Public myprice As String
Private BoxToUpdate As TextBox
Public Sub Start(ByRef txtprice As TextBox)
BoxToUpdate = txtprice
Me.ShowDialog()
End Sub
Private Sub btnSeletecPrice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeletecPrice.Click
txtPrice.Text = Me.BoxToUpdate.Text
End SubEnd Class
-
Jun 4th, 2009, 08:20 PM
#19
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
keystone_paul still not solve please help
-
Jun 5th, 2009, 02:18 AM
#20
Re: How to pass value from Independent form to child form
that part only didnot work when i pass the value from this for into the child form..
Can you clarify - you were saying you were getting an error with me.showdialog and the data not updating. Are you now saying that the me.showdialog bit is fixed?
-
Jun 5th, 2009, 03:59 AM
#21
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
yes the me.showdialog is now working...
the error now is under the click event, please see image below
Last edited by edgarbenilde; Feb 8th, 2010 at 08:29 AM.
-
Jun 5th, 2009, 04:22 AM
#22
Re: How to pass value from Independent form to child form
You don't want "Me" there - just
txtPrice.Text = BoxToUpdate.Text
-
Jun 5th, 2009, 08:36 PM
#23
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
where should i put me? me.txtprice.text or me.BoxToUpdate.text?
-
Jun 6th, 2009, 01:50 AM
#24
Re: How to pass value from Independent form to child form
Nowhere. Why do you want to put "me" there? It is not necessary. That said it shouldn't really cause a problem.
Can you show the code you are using to call the Start method? It sounds like there's a problem with the textbox you are passing in.
Last edited by keystone_paul; Jun 6th, 2009 at 01:57 AM.
-
Jun 6th, 2009, 02:04 AM
#25
Re: How to pass value from Independent form to child form
Here's my example I knocked up using two forms - frmMaster and frmDetail. frmMaster has a textbox to hold a value and a button to launch the detail form :
Code:
Public Class frmMaster
Private Sub btnShow_Detail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDetail.Click
Dim X As New frmDetail
X.Start(txtMaster)
End Sub
End Class
FrmDetail has a textbox and two buttons, clicking the btnUpdate button retrieves the value from the Master form and shows it in the textbox, the btnWriteBack button takes the text from the textbox (which the user could have edited) and writes it back to frmMaster's textbox :
Code:
Public Class frmDetail
Dim MySource As TextBox
Public Sub Start(ByRef Source As TextBox)
MySource = Source
Me.ShowDialog()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
txtDetail.Text = MySource.Text
End Sub
Private Sub btnWriteback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteback.Click
MySource.Text = txtDetail.Text
End Sub
End Class
-
Jun 7th, 2009, 07:53 PM
#26
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
is the is child form? because in my case it goes to 3 form before i can have the transaction to write back the data into child form... first when program run it will display first the 1.)MDIParent form 2.) Open child form. 3.) open an independent from the child form and do the transaction. now, my question is your frmmaster is Child form? maybe in your sample it's working but in me it did not because i has different form scenario.. thank you
-
Jun 7th, 2009, 08:00 PM
#27
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
by the way thanks keystone_Paul for your immediate responce
based on this code below how could i past the value in the also from child to independent form (FrmHistoryDetails) because when i open the FrmHistoryDetails form i have to pass also from child(frmSMRPOffline) form into indenpent form(FrmHistoryDetails) then based on the data displayed in FrmHistoryDetails i need to select one from it then send it back to child form (frmSMRPOffline), please take a look of the situation of yours and mine as kind of form (MDIParent, MDIChild form, Independent form)
thank you,
Code:
Public Class frmMaster
Private Sub btnShow_Detail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDetail.Click
Dim X As New frmDetail
X.Start(txtMaster)
End Sub
End Class
-
Jun 7th, 2009, 08:12 PM
#28
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
based on this code below, how to pass value from child to indenpendent form
i have to pass value textback value from child into independent form
1.) Item Code
2.) Item Description
based on this code
Code:
Dim X As New FrmHistorydetails
X.Start(txtpassPrice)
i have tried it like these but it did not display value...
Code:
Dim X As New FrmHistorydetails
Me.ItemCodeComboBox.Text = X.txtItemCode.Text
Me.ItemDescComboBox.Text = X.txtItemDesc.Text
me.cuscode.text = x.txtCusCode.text
X.Start(txtpassPrice)
i need to pass those value beacause i need to filter thos item has been purchase by the customer previously, so that only data from select is displayed in the form..
-
Jun 7th, 2009, 09:01 PM
#29
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
I have try this code but it did not continue display the form window independent form. it's something like there is opening in the form but it disappear again..
Code:
Private Sub LinkSeedetails_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkSeedetails.DoubleClick
X.txtItemCode.Text = Me.ItemCodeComboBox.Text
X.txtItemDesc.Text = Me.ItemDescComboBox.Text
FrmHistorydetails.passItemCode = Me.ItemCodeComboBox.Text
X.Start(txtpassPrice)
End Sub
Last edited by edgarbenilde; Jun 7th, 2009 at 09:12 PM.
-
Jun 7th, 2009, 10:49 PM
#30
Thread Starter
Fanatic Member
Re: How to pass value from Independent form to child form
nice code, i'm now done with my problem. this trade is solved already...
thanks you very much Keystone_paul for your help
here below is the original code
How i create / Show the MDIChild form from an MDIParent
Code:
Dim FrmSMRPOffline As New FrmSMRPOffline
Private Sub btnSMRPOffline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSMRPOffline.Click
Try
If Me.Label11.Text = "" Then
Me.Label11.Text = "1"
FrmSMRPOffline = New FrmSMRPOffline
FrmSMRPOffline.MdiParent = Me
FrmSMRPOffline.Show()
FrmSMRPOffline.WindowState = FormWindowState.Maximized
Else
FrmSMRPOffline.MdiParent = Me
FrmSMRPOffline.Show()
FrmSMRPOffline.WindowState = FormWindowState.Maximized
FrmSMRPOffline.BringToFront()
End If
Catch ex As Exception
End Try
End Sub
This is MDIChild form and how i pass the value from MDIChild into the Independent form
Code:
Public Class SMRP
Public X As New FrmHistorydetails
Private Sub LinkSeedetails_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkSeedetails.DoubleClick
X.passcodecust = Me.CuscodeTextBox.Text
X.passcustName = Me.CusnameComboBox.Text
X.passitemDesc = Me.ItemDescComboBox.Text
X.passItemCode = Me.ItemCodeComboBox.Text
X.Start(txtpassPrice)
End Sub
The entire code from FrmDetails to pass the value from Independent from to the MDIchild one
Code:
Public Class FrmHistorydetails
Public passitemDesc As String
Public passItemCode As String
Public passcodecust As String
Public passcustName As String
Private Sub FrmHistorydetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.txtItemCode.Text = passItemCode
Me.txtCustCode.Text = passcodecust
Me.txtCustName.Text = passcustName
Me.txtItemDesc.Text = passitemDesc
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(7).Visible = False
End Sub
Private Sub FrmHistorydetails_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Try
If Me.txtCustCode.Text <> "" Or Me.txtItemCode.Text <> "" Then
Me.SalesHistoryTableAdapter.FillByCustItem(Me.SMRPSourceDataSet.SalesHistory, Me.txtCustCode.Text, Me.txtItemCode.Text)
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(7).Visible = False
Me.SalesHistoryTableAdapter.FillByCustItem(Me.SMRPSourceDataSet.SalesHistory, Me.txtCustCode.Text, Me.txtItemCode.Text)
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).Visible = False
Me.DataGridView1.Columns(7).Visible = False
Else
End If
Catch ex As Exception
Me.Dispose()
End Try
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If Me.DataGridView1.CurrentRow IsNot Nothing Then
myrowindex = DataGridView1.CurrentRow.Index
mycellinfo = DataGridView1.Item(6, myrowindex).Value.ToString
Me.txtPrice.Text = mycellinfo
End If
Try
If txtPrice.Text <> "" Then
Dim dblTranspo As Double
dblTranspo = txtPrice.Text
txtPrice.Text = Format(dblTranspo, "#,##0.00")
Me.txtPrice.Text = Me.txtPrice.Text
End If
Catch ex As Exception
Me.txtPrice.Text = "Invalid multiplier"
Exit Sub
End Try
End Sub
Public myprice As String
Private BoxToUpdate As TextBox
Public Sub Start(ByRef txtprice As TextBox)
' Me.Close()
BoxToUpdate = txtprice
Me.ShowDialog()
End Sub
Private Sub btnSeletecPrice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeletecPrice.Click
BoxToUpdate.Text = Me.txtPrice.Text
End Sub
End Class
This code is work 100% please rate our post (me and keystone_paul) if it is usefull to you and others..
-
Jul 1st, 2009, 07:31 AM
#31
Thread Starter
Fanatic Member
Re: [RESOLVED] How to pass value from Independent form to child form
Hi i have question again, how about reverse... i wanted to pass value from child to independent form..?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|