C# 如何在WPF中刷新数据网格

C# 如何在WPF中刷新数据网格,c#,mysql,wpf,ado.net,wpfdatagrid,C#,Mysql,Wpf,Ado.net,Wpfdatagrid,我的源代码在MySQL数据库中,我已经发出了更新命令,现在我需要刷新我的DataGrid MySqlCommand cmd = new MySqlCommand( "update request set status = " + StatusRequest(value) + " where id = " + rowView[0].ToString() + "", conn); MySqlDataReader myReader = cmd.ExecuteReader(); 如何刷新我的

我的源代码在MySQL数据库中,我已经发出了更新命令,现在我需要刷新我的
DataGrid

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

如何

mydatagrid.UpdateLayout();

更新后重新加载网格的数据源

myGrid.ItemsSource = null;
myGrid.ItemsSource = myDataSource;

尝试
mydatagrid.Items.Refresh()
将您的数据网格绑定到,然后更新您的集合。

来自-


我在这方面遇到了很多麻烦,这就是帮助我用新值重新加载DataGrid的原因。确保使用从中获取数据的数据类型来获取最新的数据值

我在下面用
SomeDataType
表示了这一点

DataContext.Refresh(RefreshMode.OverwriteCurrentValues, DataContext.SomeDataType);

希望这能帮助有同样问题的人。

不是refrash,但如果我refrash程序资源更新,我需要在线refrashtime@NikhilAgrawal不适合我。我正在使用
WPF.NETCore3.1
。更新的项目怎么样?它处理更新吗?@Leonardo为此,您需要对象来实现INotifyPropertyChanged接口。这根本不起任何作用。注意:这需要
System.Data.Linq
在您的参考中对我不起作用。我正在使用
WPF.netcore3.1
。根据我的测试,这似乎比调用
GetDefaultView
要快得多,正如其他一些答案所建议的那样。
DataContext.Refresh(RefreshMode.OverwriteCurrentValues, DataContext.SomeDataType);