468,785 Members | 1,623 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,785 developers. It's quick & easy.

Refresh DataGridView

This is a two part question,

1) The code below should display a form with a datagridview and a few
command buttons. This form should allow the user to make change to the
records displayed
in the datagridview and have to changes written to the Filters table in
an MS Access database. The if the user chooses, clicking on the Restore
button empties
the contents of the Filters table, refills it with the contents of the
DefaulFilters Table, and refreshes the contents of the Datagridview to
reflect that the defaults
have been reloaded. All of this works except the part where the
datagridview gets refreshed. I can close the form and reopen it and the
default data is loaded,
but it is not loaded without closing and reopening the form. How can I
refresh the datagrid view without closing and opening the form?

2) This one may be a bit harder. The code in the Restore sub below was
built by coping, pasting, and modifing examples in the newsgroups as is most
of my code.
If someone has time, could you please write a few lines that explain
what each of the line of code are doing. I follow that a connection to
the database is open,
two DataAdapters are open for each of the two database tables, these
DataAdapters are used to fill two DataSets, and then I get lost.

Thanks for any help with either of the above.


Private Sub frmFilters_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load, MyBase.Load


End Sub

Private Sub cmdRestore_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRestore.Click

'This sub empties the Filters Table. Copies the records in the
DefaultFilters table
'and places them them in the Filters Table. Then it refreshes the
datagridviewer with the
'new records.
Dim myConnection As New OleDbConnection(strConn)
Dim ds As DataSet = New DataSet
Dim ds2 As DataSet = New DataSet
Dim tblDefaultFilters As DataTable
Dim tblCopyDefaultFilters As DataTable
'Delete all records in the FILTERS Table

cmd = New OleDb.OleDbCommand(strSQL, cn)

rdr = cmd.ExecuteReader


Dim da As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter("Select * from DefaultFilters", myConnection)
Dim da2 As OleDb.OleDbDataAdapter = New
OleDb.OleDbDataAdapter("Select * from Filters", myConnection)

tblDefaultFilters = ds.Tables(0)

Dim CB As OleDb.OleDbCommandBuilder = New

tblCopyDefaultFilters = tblDefaultFilters.Copy()

tblCopyDefaultFilters = CType(tblDefaultFilters.Clone(), DataTable)

For Each row As DataRow In tblDefaultFilters.Rows
Dim newRow As DataRow = tblCopyDefaultFilters.NewRow()
For Each col As DataColumn In tblDefaultFilters.Columns
newRow(col.ColumnName) = row(col.ColumnName)
Next col
Next row

'Clear and refill the dataset and data adapter
'then refresh the datagrid

End Sub

Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
0 8561

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by RSH | last post: by
6 posts views Thread by George | last post: by
12 posts views Thread by martin1 | last post: by
3 posts views Thread by David Cartwright | last post: by
1 post views Thread by CARIGAR | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.