You need to automatically refresh a
Use extended properties and a timer.
The sample code contains two event handlers and one method:
Sets up the sample by creating a
containing the Categories table from the Northwind database. The
default view of the table is bound to a data grid on the form. A
DataTable with the auto-refreshing
functionality is created that also contains the Categories table from
the Northwind database. The default view of the auto-refreshing table
is bound to a second data grid on the form. An extended property
RefreshTime is added to the auto-refreshing table
and set to 15 seconds—the value of the constant
DATAREFRESH_SECONDS in the sample—into the
future. Finally, a thread timer is created with a
CheckRefreshDataSet, with a due time of one
second, and a period of one second.
DataAdapter to update changes made to the
DataTable back to the data source.
This method is called periodically by the thread timer. The method
checks whether the current time is later than the time in the
RefreshTime extended property of the
auto-refreshing table. If it is, a
used to fill the table with the latest data from the data source and
RefreshTime extended property is once again
set to 15 seconds into the future.
The C# code is shown in Example 9-17.
Example 9-17. File: ...