WPF Datagrid Get Selected Cell Value

Please refer to the DataGrid Class page on MSDN. From that page: Selection By default, the entire row is selected when a user clicks a cell in a DataGrid, and a user can select multiple rows. You can set the SelectionMode property to specify whether a user can select cells, full rows, or both. Set … 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

Improve WPF DataGrid performance

There are a few options you can turn on to help you on your DataGrid object EnableColumnVirtualization = true EnableRowVirtualization = true These two are the main ones I think might help. Next try making your binding async ItemsSource=”{Binding MyStuff, IsAsync=True}” And lastly, I’ve heard that setting a maximum height and width can help even … Read more

Why can’t I style a DataGridTextColumn?

You can’t style the DataGridTextColumn because DataGridTextColumn does not derive from FrameworkElement (or FrameworkContentElement). Only FrameworkElement, etc supports styling. When you attempt to create a style in XAML for any type that is not a FrameworkElement or FrameworkContentElement you get that error message. How do you solve this? As with any problem, where there is … Read more

How can I set the color of a selected row in DataGrid

The above solution left blue border around each cell in my case. This is the solution that worked for me. It is very simple, just add this to your DataGrid. You can change it from a SolidColorBrush to any other brush such as linear gradient. <DataGrid.Resources> <SolidColorBrush x:Key=”{x:Static SystemColors.HighlightBrushKey}” Color=”#FF0000″/> </DataGrid.Resources>

DataGrid shows path of image instead of image itself

first of all, DataGrid generate DataGridTextColumns by default and we have to use AutoGeneratingColumn event to change type of column. We need to use DataGridTemplateColumn which contains Image in template (image source should be bound to correct DataTable column). The best place to define template is in Resources. here is how the issue can be … 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