When sorting and grouping, the row numbering in the DataGrid table gets confused.
<Window.DataContext> <local:MainViewModel/> </Window.DataContext> <Grid> <DataGrid x:Name="DGR" AutoGenerateColumns="False" ItemsSource="{Binding AllEmployee}" Margin="0,0,0,10"> <DataGrid.Columns> <DataGridTextColumn x:Name="ID" Binding="{Binding id}" Header="№"/> <DataGridTextColumn x:Name="Position" Binding="{Binding position}" Header="Фамилия"/> <DataGridTextColumn x:Name="Unit" Binding="{Binding unit}" Header="Группа"/> </DataGrid.Columns> <DataGrid.GroupStyle> <GroupStyle> <GroupStyle.ContainerStyle> <Style TargetType="GroupItem"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <StackPanel> <TextBlock FontWeight="Bold" Foreground="Black" FontSize="12" TextAlignment="Center" Text="{Binding Path=Name}"/> <TextBlock Foreground="Blue" FontSize="12" FontWeight="Bold" Text="{Binding ItemCount, StringFormat=Количество сотрудников в группе: {0}}" Margin="30,0,0,5" /> <ItemsPresenter/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </GroupStyle.ContainerStyle> </GroupStyle> </DataGrid.GroupStyle> </DataGrid> </Grid> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ICollectionView cvTasks = CollectionViewSource.GetDefaultView(DGR.ItemsSource); if(cvTasks != null && cvTasks.CanGroup == true) { cvTasks.GroupDescriptions.Clear(); cvTasks.SortDescriptions.Clear(); cvTasks.GroupDescriptions.Add(new PropertyGroupDescription("unit")); cvTasks.SortDescriptions.Add(new SortDescription("unit", ListSortDirection.Ascending)); } } } public class MainViewModel { public ObservableCollection<Employee> AllEmployee { get; set; } public MainViewModel() { this.Initialize(); } private void Initialize() { AllEmployee = new ObservableCollection<Employee>(); AllEmployee.CollectionChanged += OnGroceryListChanged; } void OnGroceryListChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { NumberService.SetCollection(this.AllEmployee); } } } public class Employee : ViewModelBase { private int ID { get; set; } private string Position { get; set; } private string Unit { get; set; } public int id { get { return this.ID; } set { if (value != ID) { ID = value; RaisePropertyChangedEvent("id"); } } } public string position { get { return Position; } set { if (value != Position) { Position = value; RaisePropertyChangedEvent("position"); } } } public string unit { get { return Unit; } set { if (value != Unit) { Unit = value; RaisePropertyChangedEvent("unit"); } } } } } public static class NumberService { public static ObservableCollection<T> SetCollection<T>(ObservableCollection<T> targetCollection) where T : Employee { var Number = 1; foreach (Employee sequencedObject in targetCollection) { sequencedObject.id = Number; Number++; } return targetCollection; } } } public abstract class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChangedEvent([CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { var e = new PropertyChangedEventArgs(propertyName); PropertyChanged(this, e); } } } Thanks if you help in this issue.

Id, then this is exactly the Id in the collection, but if you need a sequence number in a subcollection sorted according to some rule, then bind to this parameter calculated in the course. - Bulson<DataGridTextColumn x:Name="ID" Binding="{Binding id}" Header="№"/>- what you wrote, it happens the same. Or do you want an entity ID to change during any operation? - Andrew NOP