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:
Filling the Datagridview and displaying data in the Parent Form (List_Form_Load):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
Code:ShowFGRequisition(App.DataAccess.DAL_OrderItems.SelectRequisitionAndStatus(), dgvReqDetails)
Opening the Child Form on clicking the Action button in Parent Form:
On Closing the Child 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
What is the best way to achieve the refresh on the Parent Form using n-tier architecture?Code:List_Form.ShowFGRequisition(App.DataAccess.DAL_OrderItems.SelectRequisitionAndStatus(), List_Form.dgvReqDetails)
Any help or code correction would be highly appreciated.
Thanks
Tom


Reply With Quote
