C# DataGridView Refresh on Specified Interval
I have a best practice question. I'm building a Windows forms application in C#/.NET 4.0 where "scans" will take place behind the scenes every X seconds and update a database. I'd like to a DataGridVi开发者_开发技巧ew refresh on a specified interval to reflect the data that is now represented in the database. I plan on doing this by adding a timer to the form and on the tick event, just re-populate the DataGridView. I was wondering if this approach is the best method or if there is a more recommended way to do this?
For datagridview refresh on specified interval use multithreading with delegate.Its better for memory management.
check this
If you use an MVVM pattern an bind your datagrid data source to a collection wich raise property changed every time it's changed (Mode = TwoWay) Your data grid will be updated automatically...
private ObservableCollection<Data>_dataCollection ;
public ObservableCollection<Data> DataCollection
{
get { return _dataCollection ; }
set
{
_dataCollection = value;
RaisePropertyChanged("DataCollection ");
}
}
And the XAML code is :
<DataGrid DataSource="{Binding Mode=TwoWay, Path=DataCollection}"
DataContext="YourViewModel">
精彩评论