Category / Section
How to highlighting the newly added row in WPF DataGrid (SfDataGrid)?
1 min read
You can highlight the newly added records in WPF DataGrid (SfDataGrid) by changing its Background or Foreground color.
Follow the below steps to highlight the rows of newly added records by changing its background.
1. Add new property in data object and set it as true for newly added records in AddNewRowInitiating event as like below,
C#
this.datagrid.AddNewRowInitiating += datagrid_AddNewRowInitiating; void datagrid_AddNewRowInitiating(object sender, AddNewRowInitiatingEventArgs args) { (args.NewObject as BusinessObjects). IsNewlyAddRow= true; }
2. Create style of TargetType VirtualizingCellsControl and change the Background based on property (refer Step1) using Converter as like below,
<Window.Resources> <local:customconveter x:Key="converter"/> <Style TargetType="Syncfusion:VirtualizingCellsControl"> <Setter Property="Background" Value="{Binding Path=IsAddNewlyAddRow, Converter={StaticResource converter}}"/> </Style> </Window.Resources>
XAML
C#
public class customconveter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var IsNewlyAddRow= (bool)value; if (IsNewlyAddRow) { return Brushes.LightBlue; } return DependencyProperty.UnsetValue; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
In the same way, you can highlight the rows when you are adding record’s programmatically.
Sample: