jenn5175 Posted July 31, 2003 Posted July 31, 2003 Okay, I have 3 Windows forms - FormA, FormB, FormC. FormA is the main form which has a datagrid of all shipping containers for a certain shipment pulled from a SQL db. I use a function dgFill() on FormA to fill this when a shipment is chosen from a combobox on FormA. If the user wants to add a container, I have a cmd button on FormA which opens FormB - containing a textbox to fill in the barcode of the new container (this will eventually get changed to a barcode scanning module) and a cmd button to add container. Once the cmd button is clicked FormB hides, the new container is added, and FormC opens which allows them to add items to the new container. Once they are done adding items, I want to have a button which not only closes FormC, but refreshes the datagrid in FormA. If FormA had opened FormC I know how to reference dgFill() and call it from FormC before hiding FormC. But because FormB is the parent of FormC, I am at a loss. Simply put: FormA -> opens FormB FormB -> opens FormC FormC -> refeshes FormA I was thinking either (a) if I could call dgFill() from FormC before hiding it or (b) have some sort of "OnFocus" function on FormA so it refreshes everytime FormA is brought into focus. Any thoughts? Jenn Quote
Administrators PlausiblyDamp Posted July 31, 2003 Administrators Posted July 31, 2003 You will need to pass a reference to formA to FormB and then get formB to pass the formA reference to FormC - then formC can access FormA Hope that makes a bit of sense. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bfellwock Posted July 31, 2003 Posted July 31, 2003 From what you have written I don't see why you would have to hide formB. Why not just dispose of FormB and then Show FormC. Or just use an input box to get the barcode value i.e. myValue = InputBox(message, title, defaultValue) and then show formB. Hope this helps. Quote
jenn5175 Posted August 1, 2003 Author Posted August 1, 2003 PlausiblyDamp, How can I pass a reference for a function? Can you point me to a tutorial? I know how to pass variables but not how to pass a function reference. Thanks! Jenn Quote
Leaders dynamic_sysop Posted August 1, 2003 Leaders Posted August 1, 2003 here's a quick example i put you together : In Form1 : Dim frm2 As New Form2() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.AddOwnedForm(frm2) '/// make Form2 owned by Me End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click frm2.Show() End Sub In Form2 : Dim frm1 As Form1 Dim frm3 As New Form3() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click frm1 = Owner AddOwnedForm(frm3) frm3.Show() End Sub Public Function DoStuff(ByVal strString As String) frm1.TextBox1.AppendText(strString) End Function In Form3: Dim f2 As form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click f2 = Owner f2.DoStuff("some stuff") End Sub here's a sample source i included to make it easier to understand ...passing stuff between forms.zip Quote
Leaders dynamic_sysop Posted August 1, 2003 Leaders Posted August 1, 2003 you need to make a sort of chain , in form1 you make a new form2 , then add it as owned by form1 Dim frm2 As New Form2() '/// make it new. AddOwnedForm(frm2) '/// make Form2 owned by Form1 then when you have form2 open , you make a new Form3 , making that owned by Form2 Dim frm3 As New Form3()'/// make a new Form3 , from inside Form2. AddOwnedForm(frm3)'/// add it as owned by Form2 make a Function inside Form2 , which will pass data to Form1 ( this will be triggered via Form3 Public Function DoStuff(ByVal strString As String) frm1.TextBox1.AppendText(strString) End Function in your 3rd Form Dim f2 As form2 f2 = Owner f2.DoStuff("some stuff") the attached source will make it easier. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.