wpf: DataGrid disable selected row styles – or row selecting

figured out the XAML to get rid of selection style.. not ideal, but close enough.. <Style x:Key=”CellStyle” TargetType=”{x:Type DataGridCell}”> <Setter Property=”Foreground” Value=”Black” /> <Style.Triggers> <Trigger Property=”IsSelected” Value=”True”> <Setter Property=”Background” Value=”{x:Null}” /> <Setter Property=”BorderBrush” Value=”{x:Null}” /> </Trigger> </Style.Triggers> </Style>

How to show row-number in first column of WPF Datagrid

There might be an easier way to do this but I got it to work by using the GetIndex() method on the DataGridRow class. This returns the index in to the data source so might not be exactly what you’re after. the xaml <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:sys=”clr-namespace:System;assembly=mscorlib” xmlns:local=”clr-namespace:WpfApplication1″ Title=”MainWindow” Height=”350″ Width=”525″> <DataGrid> <DataGrid.Columns> <DataGridTextColumn … Read more

How to access datagrid template column textbox text WPF C#

To find a control in a DataGrid template column, you should use FindChild(): public static T FindChild<T>(DependencyObject parent, string childName) where T : DependencyObject { if (parent == null) { return null; } T foundChild = null; int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(parent, … 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

Simple way to display row numbers on WPF DataGrid

One way is to add them in the LoadingRow event for the DataGrid <DataGrid Name=”DataGrid” LoadingRow=”DataGrid_LoadingRow” … void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = (e.Row.GetIndex()).ToString(); } When items are added or removed from the source list then the numbers can get out of sync for a while. For a fix to this, see the … Read more

WPF horizontal DataGrid

I’ve done this earlier since we wanted to be able to use the same control for a DataGrid and a PropertyGrid. Alot of things have to be changed (like alignment, scrolling, positioning of sort-arrows etc.). There is way to much code to post the whole solution but this should get you started. This is an … Read more