[RESOLVED] Refresh DataGridView on Parent Form on/after closing child form
Hi All,
I am using n-tier architecture to develop a database application using Winforms and SQL Server. One of the forms has a datagridview. Each row of the datagridview has an action button which is based on certain status of the data. When clicked a child form is opened (not for the same table or data). However saving data from the child form will update the status of the record displayed in the Parent form. This should change the caption of the Action button accordingly or remove the record from the datagridview (if no longer meeting the criteria for the records to be displayed). I am trying to refresh the datagridview on the parent form to display the changed status or the row being removed, but it does not refresh. My code is as below:
Populating the Datagridview on the Parent Form:
Code:
Public Sub ShowFGRequisition(ByVal data As DataSet, ByVal dgv As DataGridView)
dgv.DataSource = data.Tables(0)
dgv.Columns(0).Width = 60
dgv.Columns(0).HeaderText = "Requisition"
dgv.Columns(1).Width = 0
dgv.Columns(1).HeaderText = "Code"
dgv.Columns(2).Width = 130
dgv.Columns(2).HeaderText = "Name"
dgv.Columns(3).Width = 85
dgv.Columns(3).HeaderText = "UOM"
dgv.Columns(4).Width = 65
dgv.Columns(4).HeaderText = "Qty."
dgv.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
dgv.Columns(4).DefaultCellStyle.Format = "N2"
dgv.Columns(5).Width = 70
dgv.Columns(5).HeaderText = "Stock"
dgv.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
dgv.Columns(5).DefaultCellStyle.Format = "N2"
dgv.Columns(6).Width = 85
dgv.Columns(6).HeaderText = "Status"
dgv.Columns(7).Width = 135
dgv.Columns(7).HeaderText = "Action"
dgv.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
dgv.Columns(8).Width = 0
dgv.Columns(8).HeaderText = "NoOfRMItems"
End Sub
Filling the Datagridview and displaying data in the Parent Form (List_Form_Load):
Code:
ShowFGRequisition(App.DataAccess.DAL_OrderItems.SelectRequisitionAndStatus(), dgvReqDetails)
Opening the Child Form on clicking the Action button in Parent Form:
Code:
Private Sub dgvReqDetails_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvReqDetails.CellClick
If dgvReqDetails.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString = "W/Order" Then
New_WOrderForm.ShowDialog()
End If
End Sub
On Closing the Child Form:
Code:
List_Form.ShowFGRequisition(App.DataAccess.DAL_OrderItems.SelectRequisitionAndStatus(), List_Form.dgvReqDetails)
What is the best way to achieve the refresh on the Parent Form using n-tier architecture?
Any help or code correction would be highly appreciated.
Thanks
Tom
Re: Refresh DataGridView on Parent Form on/after closing child form
The dialogue should not be making any reference to the calling form. You should have the dialogue set its DialogResult property to close. Whatever value you set will be returned by the ShowDialog call in the calling form. If that value is OK then the calling form knows that it needs to refresh its grid from the database or some local cache.
Re: Refresh DataGridView on Parent Form on/after closing child form