I tested it with the code below. You could see if it helps you.
I also tested your code and it seems to work fine. Can you point out where the specific problem is?
According to official documentation Default keyboard and mouse behavior in DataGrid control.
ENTER Commits any changes to the current cell and row, and moves focus to the cell directly below the current cell. If focus is on the last row, commit any changes without moving focus.
MainWindow.xaml:
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<Grid>
<DataGrid x:Name="dg" ItemsSource="{Binding Users}" SelectedItem="{Binding SelecedItme }" AutoGenerateColumns="False" CanUserAddRows="True" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="Id" Binding="{Binding Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="Id" />
<DataGridTextColumn x:Name="Name" Binding="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="Name" />
</DataGrid.Columns>
</DataGrid>
</Grid>
using System.Windows;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace DataGridNextRowCell
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class ViewModel : INotifyPropertyChanged
{
private User selecedItme;
public User SelecedItme
{
get { return selecedItme; }
set
{
if (selecedItme != value)
{
selecedItme = value;
OnPropertyChanged("SelecedItme");
}
}
}
private ObservableCollection<User> users = new ObservableCollection<User>();
public ObservableCollection<User> Users
{
get { return users; }
set
{
if (users != value)
{
users = value;
OnPropertyChanged("Users");
}
}
}
public ViewModel()
{
Users.Add(new User() { Id = 1, Name = "user1" });
Users.Add(new User() { Id = 2, Name = "user2" });
Users.Add(new User() { Id = 3, Name = "user3" });
Users.Add(new User() { Id = 5, Name = "user4" });
Users.Add(new User() { Id = 6, Name = "user5" });
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
}
The result of my test (press Enter):
The results of testing your code (press Enter):
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.