How to refresh datagrid in WPF

前端 未结 6 1371
慢半拍i
慢半拍i 2020-12-08 02:48

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(
  \"u         


        
相关标签:
6条回答
  • 2020-12-08 03:24

    Reload the datasource of your grid after the update

    myGrid.ItemsSource = null;
    myGrid.ItemsSource = myDataSource;
    
    0 讨论(0)
  • 2020-12-08 03:28

    Try mydatagrid.Items.Refresh()

    0 讨论(0)
  • 2020-12-08 03:30

    Bind you Datagrid to an ObservableCollection, and update your collection instead.

    0 讨论(0)
  • 2020-12-08 03:31

    I had a lot of trouble with this and this is what helped me get the DataGrid reloaded with the new values. Make sure you use the data type that your are getting the data from to get the latest data values.

    I represented that with SomeDataType below.

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

    Hope this helps someone with the same issues I had.

    0 讨论(0)
  • 2020-12-08 03:33

    From MSDN -

    CollectionViewSource.GetDefaultView(myGrid.ItemsSource).Refresh();
    
    0 讨论(0)
  • 2020-12-08 03:34

    How about

    mydatagrid.UpdateLayout();
    
    0 讨论(0)
提交回复
热议问题