Refresh datagrid on one form from another

ahbenshaut

Well-known member
Joined
Oct 29, 2004
Messages
62
Location
Alaska
Programming Experience
5-10
Ok, the title may be confusing so some here is what I would like to happen:
1. Form "Orders" has a datagrid that shows unprocessed records and a "Process" button.
2. User clicks "Process" and a Printable form is displayed as a receipt. User clicks "Print" button on receipt, receipt is printed, receipt form is closed and the datagrid on the "Orders" form is updated.

So far the only thing I cant figure out is how to get the datagrid to refresh. Any help would be greatly appreciated. Also, if there is an easier way of doing this process, that would be helpful too.

TIA
 
If you are wanting to access the datagrid on the Orders form, you will want to pass the Orders form to your second form as a parameter in your second form's constructor. In other words:

Public Class OrderForm
Inherits System.Windows.Forms.Form


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim printform As PrintableForm = New PrintableForm(Me)
End Sub

End
Class

Public
Class PrintableForm
Inherits System.Windows.Forms.Form

Dim OrdForm As OrderForm

Public Sub New(ByVal frm As OrderForm)
MyBase.New()
'Other initialization stuff
OrdForm = frm
End Sub

Private Sub UpdateDatagrid()
OrdForm.DataGrid1.Refresh()
End Sub

End Class
 
Process button

This all depends on what happens when unprocessed Orders are processed. When the process button is pressed, are the records actually processed first and then printed or do you print them and then process? What happens to the unprocessed record after it is processed? Does it disappear from the grid, is a field updated, etc...

Your solution could be as simple as a call to update the dataset followed by a call to reload the updated dataset to reflect the changes/deletions made.
 
Back
Top