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.

Thomas

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

Me.FiltersTableAdapter.Fill(Me.TAMDataSet.Filters)

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
strSQL = "DELETE * FROM FILTERS"

cmd = New OleDb.OleDbCommand(strSQL, cn)

rdr = cmd.ExecuteReader

myConnection.Open()

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

da.Fill(ds)
da2.Fill(ds2)
tblDefaultFilters = ds.Tables(0)

Dim CB As OleDb.OleDbCommandBuilder = New
OleDb.OleDbCommandBuilder(da2)

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
tblCopyDefaultFilters.Rows.Add(newRow)
Next row

da2.Update(tblCopyDefaultFilters)
'Clear and refill the dataset and data adapter
'then refresh the datagrid
Me.TAMDataSet.Clear()
Me.FiltersTableAdapter.Fill(Me.TAMDataSet.Filters)
Me.DataGridView1.Refresh()
myConnection.Close()

End Sub

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
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.