How can I set the position of my datagrid scrollbar in my winforms app?

You don’t actually interact directly with the scrollbar, rather you set the FirstDisplayedScrollingRowIndex. So before it reloads, capture that index, once it’s reloaded, reset it to that index. EDIT: Good point in the comment. If you’re using a DataGridView then this will work. If you’re using the old DataGrid then the easiest way to do … Read more

DataGrid column width doesn’t auto-update

The DataGrid will increase column sizes to fit as the data becomes longer, but it does not automatically decrease column sizes when the length of the data decreases. In your example, you’re right aligning the ‘Change’ column, and using the rest of the space for the ‘Name’ column. Now, when a ‘Change’ property grows large … Read more

How to create style based on default DataGrid style?

Well mystery is solved 🙂 My first code above actually works: <Style TargetType=”{x:Type MyControls:ExtendedDataGrid}” BasedOn=”{StaticResource {x:Type DataGrid}}”> <Setter Property=”Template”> … </Setter> </Style> I thought that it is not working becase VS (or Resharper) showed error in my code saying that resource is not found… Bug in VS (or Resharper) 🙁

How to center the content of cells in a data grid?

Final solution: <Style x:Key=”DataGridContentCellCentering” TargetType=”{x:Type DataGridCell}”> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”{x:Type DataGridCell}”> <Grid Background=”{TemplateBinding Background}”> <ContentPresenter VerticalAlignment=”Center” /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>