|
-
Oct 5th, 2003, 08:51 PM
#1
Thread Starter
Lively Member
How to call from 1 form to another form?
Hi, i have enquires regarding the calling of form 1 to form 2.
I wan to make use of form 1 function which is to be called from form 2. How do i achieve it?
Can u show mi some examples?
-
Oct 5th, 2003, 09:24 PM
#2
Frenzied Member
For example this goes in form1
VB Code:
Public Function multiply(ByVal x As Integer, ByVal y As Integer) As Integer
Return x * y
End Function
and you call it in form2 like this in a desired event:
VB Code:
Dim frm As New Form1
MessageBox.Show(frm.multiply(10, 20))
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 09:30 PM
#3
Thread Starter
Lively Member
Like, if i got form 1 clear form hor, which i make is
public sub clearform()
datagrid1 clear()
dataset1.clear()
end sub
Then in form 2, i wan to close this form, which is able to refresh my datagrid and dataset.
How to do it?
-
Oct 5th, 2003, 09:43 PM
#4
Frenzied Member
Describe it a bit more clear. I am afraid you need more than what i provided for you in previous post.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 09:50 PM
#5
Thread Starter
Lively Member
ok... My form1 is for searching of records, when e user enter the search name, then click search, then it will display a datagrid showing the search record.
When click on e datagrid, then it will show e record in each of e respective textbox, that will be my form2.
When he edit the record, it will save into e database n close e form. Then the form1 will clear all the search record from e datagrid and enable the user to re serach again OR e datagrid will display the edited record.... (I will be doing in either way)
-
Oct 5th, 2003, 09:56 PM
#6
Frenzied Member
Ok, so why not doing it in this way. When the user clicks on the datagrid then you show From2 modally, that is ShowDialog. So it suspends the rest of the procedure until Form2 is closed. Then after returning you call 'clearform'. So you dont need to refresh Form1 in closing event of Form2.
VB Code:
' This goes where you catch the user click on the datagrid
Dim frm as New Form2
frm.ShowDialog
' this is done after form2 is closed
Me.clearform()
'
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 09:58 PM
#7
Thread Starter
Lively Member
i not doing in dialog form lei, i use form one... how to do in form one? Got any other methods?
-
Oct 5th, 2003, 10:00 PM
#8
Frenzied Member
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 10:13 PM
#9
Thread Starter
Lively Member
Oh, i got it liao, Thanks.. I can clear the form.
But if i wan to close e form2, then i wan display e edited record, how to do ah?
-
Oct 5th, 2003, 10:13 PM
#10
in Form1.....
VB Code:
Dim frm2 As New Form2()
MyBase.AddOwnedForm(frm2)'/// add it as owned by Form1.
frm2.Show()
Private Sub testing()
MessageBox.Show("i was triggered from Form2!")
End Sub
then in Form2 ( to call the sub in Form1 / to call any functions you have in Form1 ) ....
VB Code:
'/// within a button click event etc...
Dim frmMain As Form1 = Me.Owner
frmMain.testing() '/// call the sub on Form1 here.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Oct 5th, 2003, 10:21 PM
#11
Frenzied Member
Originally posted by berrie_luv
Oh, i got it liao, Thanks.. I can clear the form.
But if i wan to close e form2, then i wan display e edited record, how to do ah?
I think you have to refetch the data from database. But it really depends on your design. You may use the same instance of your dataset in form2 and updating that will refelect back to form1 too, I don't kow if it makes sense for you.
Last edited by Lunatic3; Oct 5th, 2003 at 10:47 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 10:35 PM
#12
Thread Starter
Lively Member
Originally posted by Lunatic3
Ok, so why not doing it in this way. When the user clicks on the datagrid then you show From2 modally, that is ShowDialog. So it suspends the rest of the procedure until Form2 is closed. Then after returning you call 'clearform'. So you dont need to refresh Form1 in closing event of Form2.
VB Code:
' This goes where you catch the user click on the datagrid
Dim frm as New Form2
frm.ShowDialog
' this is done after form2 is closed
Me.clearform()
'
E form cannot use again... cos when i click e datagrid hor, e textbox onli show e first record, i selected the rest, still show e 1st record. Wat should i do? Help...
-
Oct 5th, 2003, 11:16 PM
#13
Thread Starter
Lively Member
Can u pls help mi... i need to complete this urgently. When selecting the 3rd record or others, it onli show e 1st record...
How to debug this error?
-
Oct 5th, 2003, 11:24 PM
#14
Frenzied Member
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 11:39 PM
#15
Thread Starter
Lively Member
Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
Dim i As Integer
For i = 0 To 7
staffArray(i) = DataGrid1.Item(DataGrid1.CurrentRowIndex, i)
Next
Dim frm As New frmViewStaff()
frm.ShowDialog()
Me.clearForm()
End Sub
This is my codes when e datagrid is clicked.
-
Oct 5th, 2003, 11:45 PM
#16
Frenzied Member
and in form2 what happens there? send the whole project if you dont mind.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 11:51 PM
#17
Thread Starter
Lively Member
The other form is just view in e textbox loh.... i store them in array from e datagrid then pass to this form2.
Private Sub frmViewStaff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtSur.Text = staffArray(0)
txtName.Text = staffArray(1)
txtStaffNo.Text = staffArray(3)
txtDes.Text = staffArray(4)
txtDep.Text = staffArray(5)
txtExt.Text = staffArray(6)
txtEmail.Text = staffArray(7)
End Sub
Is there any prob with the form1?
-
Oct 5th, 2003, 11:58 PM
#18
Frenzied Member
I see no problem with your code, if you are passing the staffarray to frmViewStaff correct then there should be no problem. How you do that?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 5th, 2003, 11:59 PM
#19
Thread Starter
Lively Member
yaya.. but i dun noe y there is error over here. If i never do e codes u given mi, then everything works out fine. Is there any other way compared to e showDialog one?
-
Oct 6th, 2003, 12:02 AM
#20
Frenzied Member
I guess it has nothing to do with showdialog. You better send me the whole project so i can examine it for you.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 6th, 2003, 01:41 AM
#21
Thread Starter
Lively Member
Sorry ah, i cannot post e whole pj here.
When i click e datagrid, too many times, it will display that the index was out of bound. Wat happen ah? Then sometimes the selection will display wrong data.
-
Oct 6th, 2003, 01:58 AM
#22
Frenzied Member
out of bonds of what? the array or related to datagrid?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 6th, 2003, 01:59 AM
#23
Thread Starter
Lively Member
Yaya, dunnoe why... so weird one. U know?
-
Oct 6th, 2003, 02:09 AM
#24
Frenzied Member
well if you have followed the rules properly then it sohuld not happen. I know nothing about your desgin and I am affraid i cant help you without knowing exactly what you are doing and how you have coded.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 6th, 2003, 02:11 AM
#25
Thread Starter
Lively Member
Is there any other method other than the showDialog one?
-
Oct 6th, 2003, 02:16 AM
#26
Frenzied Member
to show another form from your form you can use Show or ShowDialog. In latter case the execution of code in the first form is suspeneded untill the secod form is closed,but in first the codes after that continues to run.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 6th, 2003, 02:32 AM
#27
Thread Starter
Lively Member
I tink showDialog is a gd method, but will there be any problem regarding my array? Is array suitable in the showDialog method?
-
Oct 6th, 2003, 02:35 AM
#28
Frenzied Member
Where you have declared your array? how you pass it to the second form?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 6th, 2003, 02:38 AM
#29
Thread Starter
Lively Member
I declare the array as module.
Module module1
Public staffArray(7) As String
End Module
Then pass the module to my form2, which is in e form load
Private Sub frmViewStaff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtSur.Text = staffArray(0)
........................................
........................................
end sub
-
Oct 6th, 2003, 02:46 AM
#30
Frenzied Member
well, i really cant say whats wrong. I just saw a minor point in your code that maybe not important.
txtName.Text = staffArray(1)
txtStaffNo.Text = staffArray(3)
You dont use staffArray(2)? Does your datagrid have 8 or 7 columns?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Oct 6th, 2003, 02:52 AM
#31
Thread Starter
Lively Member
should be like this, all will be used.
Private Sub frmViewStaff_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtSur.Text = staffArray(0)
txtName.Text = staffArray(1)
txtNUSNo.Text = staffArray(2)
txtStaffNo.Text = staffArray(3)
txtDes.Text = staffArray(4)
txtDep.Text = staffArray(5)
txtExt.Text = staffArray(6)
txtEmail.Text = staffArray(7)
End Sub
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
|