prowebinteractiveinc
asked on
DataGridView Refresh from child Form
my main form is a datagrid view of customers, I have a menuStrip with icons where I can add customers which opens a child form, when i click on the cave button I would like to close the child form and update the parent form, how can I do this ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is easy but it requires that Child Form knows Parent Form. This breaks encapsulation concept.
I think you do´nt need do it from parent form.
You are using a modal child form. Then use the DialogResult.
Note that there are some Dialog Result values.
You assign a Dialog Result to each Button on Child Form that terminates the action (Ok, CanCel, Yes ...)
Dim Result = ChildForm.ShowDialog
Select Case ReSult
Case DialogResult.Ok
Refresh the Dgv
Case DialogResult.Cancel
Other Options
Note that when you press a button with DialogResult asigned, ChildForm is closed.
I think you do´nt need do it from parent form.
You are using a modal child form. Then use the DialogResult.
Note that there are some Dialog Result values.
You assign a Dialog Result to each Button on Child Form that terminates the action (Ok, CanCel, Yes ...)
Dim Result = ChildForm.ShowDialog
Select Case ReSult
Case DialogResult.Ok
Refresh the Dgv
Case DialogResult.Cancel
Other Options
Note that when you press a button with DialogResult asigned, ChildForm is closed.
ASKER
I dont expect someone to just write my code for me, however I just opened VB.NET for the first time, last week, and have poking around since.. is there some sample code you can show me, the code above is where I need the parent refresher
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\users\jason\documents\visual studio 2010\Projects\WindowsApplication2\WindowsApplication2\Database1.mdb;")
cn.Open()
str = "INSERT INTO customers (customer_fname, customer_lname) VALUES('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "')"
cmd = New OleDbCommand(str, cn)
cn.Close()
<!-- THIS IS WHERE I NEED REFRESH CODE -->
Me.Close()
End Sub
Dim Dt as new DataTable, Da as new OleDbDatAdapter(cmd)
Da.Fill(Dt)
TheDgv.DataSource = Dt
ASKER
Ive played around with what you gave me and I cant get it to work ??
ASKER