You may have tried to select a row in a DataGrid in WPF programmatically by setting its
Define a DataTable in the view model. Define columns (In my case I had to define columns programmatically within a foreach loop). Add rows. Then bind the DataTable for the ItemsSource property of the datagrid.
(However I am not sure whether or not this is in line with most guidelines, like MVVM). option 1: like JohnB said.
The default control template of the built-in DatePicker control in WPF and MVVM · How to programmatically select and focus a row or cell
WPF DataGrid, selected row color on DataGrid SelectedItem Change in MVVM.
This is because the arrows are not part of the ColumnHeader template; instead, they are added programmatically.
In this post we will see how to add rows and columns to a Grid in WPF programmatically using code behind.
WPF DataGrid: How to clear selection programmatically?
I have prepared the sample using MVVM with the help of DataGrid in WPF.
See if that helps you at all. Related questions. How to add rows with a DataGrid and MVVM. I have a WPF MVVM app that contains an editable DataGrid.