Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh datagrid in WPF

My source is in a MySQL database, I've made an update command and now I need to refresh my DataGrid.

MySqlCommand cmd = new MySqlCommand(   "update request set status = " + StatusRequest(value) +    " where id = " + rowView[0].ToString() + "", conn); MySqlDataReader myReader = cmd.ExecuteReader(); 

How do I refresh my DataGrid?

like image 599
Johniek Comp Avatar asked Jul 04 '12 07:07

Johniek Comp


People also ask

How to refresh DataGrid in wpf mvvm?

Set your data item to ObservableCollection and bind itemSource of dataGrid with ObservableCollection . Datagrid will be refreshed if entries will be added/removed or moved to this collection.

How do you refresh a data grid?

Use the dataGrid. refresh method. Use the reload() method of your DataGrid's dataSource as shown in the following help topic: cacheEnabled. Create a new instance of a store and assign it to your DataGrid's dataSource.


2 Answers

Try mydatagrid.Items.Refresh()

like image 154
abramlimpin Avatar answered Sep 22 '22 12:09

abramlimpin


Reload the datasource of your grid after the update

myGrid.ItemsSource = null; myGrid.ItemsSource = myDataSource; 
like image 36
JohnnBlade Avatar answered Sep 19 '22 12:09

JohnnBlade