Groups | Blog | Home
all groups > vb.net controls > august 2004 >

vb.net controls : Refresh datagrid on main form from sub form


m_doolio NO[at]SPAM hotmail.com
8/20/2004 7:46:57 AM
I've got 2 forms:

1 main form with a datagrid (dgCurOrder) and one small form for
OrderEntry

When the user adds a record to the datatable
(OrderDs.Tables("orderregels"))
the record's added I can update the underlying access database with
the dataadapter.

But I cannot refresh the datagrid (dgCurOrder) on my other form...
The datagrid is bound to the above dataset, I can tell that the
records are added, etc, etc.

Here's a snippet:

Private Sub VoegOrderregelToe()
Dim rowVals(4) As Object
Dim rc As DataRowCollection
Dim myNewRow As DataRow

rc = OrderDs.Tables("orderregels").Rows

rowVals(0) = MyDebiteur
rowVals(1) = txtItem.Text 'Artikel
rowVals(2) = txtAantal.Text 'Aantal
rowVals(3) = MyOrderEntryNr 'OrderEntry
rowVals(4) = lblDescription.Text 'Omschrijving
' Add and return the new row.
myNewRow = rc.Add(rowVals)

Dim MyForm As New frmCurOrder 'This is the main form
myOrderRegelAdapter.Update(OrderDs, "orderregels")
MyForm.dgCurOrder.DataSource = OrderDs.Tables("orderregels")
MyForm.dgCurOrder.Refresh()
End Sub

Thanks in advance!

Ken Tucker [MVP]
8/21/2004 7:18:41 AM
Hi,

You are creating a new main form and setting the datasource for
the datagrid on the new form which you have not shown yet. You need to pass
a reference to the main form when you open the second form so you can update
the form you are seeing.

Ken
---------------------
[quoted text, click to view]
I've got 2 forms:

1 main form with a datagrid (dgCurOrder) and one small form for
OrderEntry

When the user adds a record to the datatable
(OrderDs.Tables("orderregels"))
the record's added I can update the underlying access database with
the dataadapter.

But I cannot refresh the datagrid (dgCurOrder) on my other form...
The datagrid is bound to the above dataset, I can tell that the
records are added, etc, etc.

Here's a snippet:

Private Sub VoegOrderregelToe()
Dim rowVals(4) As Object
Dim rc As DataRowCollection
Dim myNewRow As DataRow

rc = OrderDs.Tables("orderregels").Rows

rowVals(0) = MyDebiteur
rowVals(1) = txtItem.Text 'Artikel
rowVals(2) = txtAantal.Text 'Aantal
rowVals(3) = MyOrderEntryNr 'OrderEntry
rowVals(4) = lblDescription.Text 'Omschrijving
' Add and return the new row.
myNewRow = rc.Add(rowVals)

Dim MyForm As New frmCurOrder 'This is the main form
myOrderRegelAdapter.Update(OrderDs, "orderregels")
MyForm.dgCurOrder.DataSource = OrderDs.Tables("orderregels")
MyForm.dgCurOrder.Refresh()
End Sub

Thanks in advance!

Mike

m_doolio NO[at]SPAM hotmail.com
8/21/2004 1:54:19 PM
Ken,

When I open the second form the datasource for the datagrid (on the
mainform) is already set, I'm setting it on the new form just to be
sure it's set..
Here's my code which creates the second form:

Dim FrmArtikel As New frmArticleEntry
FrmArtikel.ShowDialog()

Can you please show me how I pass a reference?

Thanks in advance,

Mike

[quoted text, click to view]
Ken Tucker [MVP]
8/22/2004 5:59:39 PM
Hi,

This will change the text in form1 from form2.
Dim frm As New Form2

frm.Owner = Me

frm.ShowDialog()



In owned form

DirectCast(Me.Owner, Form1).Text = "Live from form2"



Ken

-------------------------

[quoted text, click to view]
Ken,

When I open the second form the datasource for the datagrid (on the
mainform) is already set, I'm setting it on the new form just to be
sure it's set..
Here's my code which creates the second form:

Dim FrmArtikel As New frmArticleEntry
FrmArtikel.ShowDialog()

Can you please show me how I pass a reference?

Thanks in advance,

Mike

[quoted text, click to view]

m_doolio NO[at]SPAM hotmail.com
8/23/2004 7:18:57 AM
Thanks a million Ken!

DirectCast(Me.Owner, frmOrderEntry).dgCurOrder.DataSource =
OrderDs.Tables("orderregels")

Did the trick.

Regards,

Mike

[quoted text, click to view]
AddThis Social Bookmark Button