WPF DataGrid: how do I stop auto scrolling when a cell is clicked?

Define an EventSetter in the DataGrid.RowStyle to call a handler that prevents the row from being brought into view: XAML <DataGrid> <DataGrid.RowStyle> <Style TargetType=”{x:Type DataGridRow}”> <EventSetter Event=”Control.RequestBringIntoView” Handler=”DataGrid_Documents_RequestBringIntoView” /> </Style> </DataGrid.RowStyle> </DataGrid> Handler private void DataGrid_Documents_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) { e.Handled = true; }

WPF DataGrid RowHeader databinding

I tried both answers, and neither worked for me. Essentially what I had to do was mix them together. This works for me: <DataGrid name=”ui_dataGrid> <DataGrid.RowHeaderTemplate> <DataTemplate> <TextBlock Text=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=Item.Header}”/> </DataTemplate> </DataGrid.RowHeaderTemplate> </DataGrid> The trick is to find the ancestor DataGridRow, then Bind the TextBlock.Text attribute to its Item’s property that … Read more

Re-sort WPF DataGrid after bounded Data has changed

It took me the whole afternoon but I finally found a solution that is surprisingly simple, short and efficient: To control the behaviors of the UI control in question (here a DataGrid) one might simply use a CollectionViewSource. It acts as a kind of representative for the UI control inside your ViewModel without completely breaking … Read more

Sort a wpf datagrid programmatically

voo’s solution was not working for me, ItemsSource was null, most likely because it was not directly set, but bound. All other solutions I found here at StackOverflow were dealing with sorting the Model only, but the DataGrid header was not reflecting to the sort. Here’s a proper solution based on the incomplete script here: … Read more

WPF Datagrid Performance

Since I can’t see your source code it is quite hard to help you. Especially since the performance of a WPF application is influenced by a lot of things. For some hints on what to look out for see Optimizing WPF Application Performance. And yes – it greatly matters what xaml is used in each … Read more

WPF datagrid header text binding

This is the easy way to bind the DataGridTextColumn header to the data context: <DataGrid x:Name=”summaryGrid” Grid.Row=”3″ AutoGenerateColumns=”False” IsReadOnly=”True” CanUserAddRows=”False”> <DataGrid.Columns> <DataGridTextColumn Header=”Hard Coded Title” Width=”*”/> <DataGridTextColumn Width=”100″> <DataGridTextColumn.Header> <TextBlock Text=”{Binding DataContext.SecondColumnTitle, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}”/> </DataGridTextColumn.Header> </DataGridTextColumn> <DataGridTextColumn Width=”150″> <DataGridTextColumn.Header> <TextBlock Text=”{Binding DataContext.ThirdColumnTitle, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}”/> </DataGridTextColumn.Header> </DataGridTextColumn> </DataGrid.Columns> </DataGrid> You will obviously need to … Read more

Datagrid in WPF – 1 column default sorted

NOTE: Using a CollectionViewSource will provide you with more power and control in these situations. When you’re learning WPF I recommend understanding how to use CollectionViewSource to solve this problem along with other collection related problems like Grouping and Filtering. EDIT: This may be due to changes in the specification. This answer is based upon … Read more

How do I dynamically generate columns in a WPF DataGrid?

Ultimately I needed to do two things: Generate the columns manually from the list of properties returned by the query Set up a DataBinding object After that the built-in data binding kicked in and worked fine and didn’t seem to have any issue getting the property values out of the ExpandoObject. <DataGrid AutoGenerateColumns=”False” ItemsSource=”{Binding Results}” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)