473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 9565

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RSH | last post by:
Hi, I have a situation where I have a DDL that lists all of the tables in a particular database, and a Datagridview which appears in the same from below the DDL.. When the user selects a new...
6
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to...
12
by: martin1 | last post by:
All, is there window form refresh property? I try to set up window form refresh per minute. Thanks
2
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and...
3
by: David Cartwright | last post by:
Hi all, I'm having a weird time with a call to the Refresh() method of a DataGridView. I have a VB.NET 2005 Windows application with a main form and a "worker" thread. The main form delegates a...
7
by: mvenkatesan | last post by:
Hi guys I am win appl. I was bind the datagridview from datatable. i was changed datas @ runtime. datatable changed but my datagridview not refresh. I written dagaridview.refresh(); not work ...
1
by: MFayaz | last post by:
Hello! I have to refresh datagridview when database update , IS there any way to solution that my datagridview auto refresh when any user update database. Thanks in Advance
2
by: YouPoP | last post by:
Hi, I have a Window Form to which i added a datagridview. The binding source is working well, but does not update if the database is modified outside the application (i mean not showing the...
1
by: Aegixx | last post by:
Ok, extremely wierd situation here: (I'll post the code below, after the explanation) I've got a Windows application (.NET 3.5) that has a single Form with a DataGridView embedded. The user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.