I still can't find where my mistake is.

The sample code you sent me works perfectly, I am very grateful. I made a few corrections, but I can't figure out where my error is in my code. The instructions are similar, but I can't see why in my code it does the row change when I just want it to jump to the column.  I'm completely new to SyncFusion. I'm coming from WinForms, so I haven't fully adapted to these controls. I don't know if I should send the full code or just what's relevant to my problem.

<Window

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:MyProyect.Views"

        xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="MyProyect.Views.wRutasCatalogo"

        Loaded="Window_Loaded" mc:Ignorable="d"

        Title="wMainCatalogo" Height="450" Width="1300">

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="Auto" />

            <ColumnDefinition Width="2*" />

            <ColumnDefinition Width="70" />

        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>

            <RowDefinition Height="40" />

            <RowDefinition Height="*" />

            <RowDefinition Height="40" />

        </Grid.RowDefinitions>

        <syncfusion:SfDataGrid x:Name="sfDg1" ItemsSource="{Binding LasRutas}"

                                AutoGenerateColumns="False" AllowEditing="True"

                                Height="Auto" Width="Auto" Grid.Column="1" Grid.Row="1"

                                SelectionMode="Single">

            <syncfusion:SfDataGrid.Columns>

                <syncfusion:GridNumericColumn MappingName="RowID" HeaderText="RowID" IsReadOnly="False" />

                <syncfusion:GridNumericColumn MappingName="Consec" HeaderText="No."/>

                <syncfusion:GridTextColumn MappingName="RutaNombre" HeaderText="Nombre Ruta"/>

                <syncfusion:GridNumericColumn MappingName="GestorID" HeaderText="ID Gestor"/>

                <syncfusion:GridTextColumn MappingName="GestorNombres" HeaderText="Gestor"/>

            </syncfusion:SfDataGrid.Columns>

        </syncfusion:SfDataGrid>

    </Grid>

</Window>


using dg = MyProject.Utilitarios.dgUtilities;

using Syncfusion.UI.Xaml.Grid;

using Syncfusion.UI.Xaml.ScrollAxis;


public partial class wMainCatalogo : Window

{

    private MaeRutasEngine ViewModel;


    public wMainCatalogo(MainCatalogoEngine _viewModel)

    {

        InitializeComponent();

        ViewModel = _viewModel;

        DataContext = ViewModel;


        sfDg1.AddHandler(

            UIElement.PreviewKeyDownEvent,

            new KeyEventHandler(sfDg1_PreviewKeyDown),

            handledEventsToo: true);

    }


    private async void Window_Loaded(object sender, RoutedEventArgs e)

    {

       await ViewModel.LoadRutas();

    }


    private void sfDg1_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)

    {


        if (e.Key == Key.Enter && sfDg1.IsKeyboardFocusWithin)

        {


            SfDataGrid? grid = sender as SfDataGrid;


            if (!grid.SelectionController.CurrentCellManager.HasCurrentCell) return;

            if (grid == null) return;


            grid.SelectionController.CurrentCellManager.EndEdit();

    dg.GoToNextEditableCell(grid);

            e.Handled = true;

        }


    }

}


using Syncfusion.UI.Xaml.Grid;

using Syncfusion.UI.Xaml.ScrollAxis;

public static void GoToNextEditableCell(SfDataGrid grid)

{

    var manager = grid.SelectionController.CurrentCellManager;

    if (manager == null || !manager.HasCurrentCell) return;



    var current = manager.CurrentRowColumnIndex;

    int rowIndex = current.RowIndex;

    int colIndex = current.ColumnIndex;

    //RowColumnIndex rowColumnIndex1 = new RowColumnIndex();


    for (int c = colIndex + 1; c < grid.Columns.Count; c++)

    {

        var col = grid.Columns[c];

        if (!col.IsHidden && col.AllowEditing)

        {

            var nextCell = new RowColumnIndex(rowIndex, c);

            // This is my previous instruction.

            //grid.MoveCurrentCell(nextCell,false);

    // I have changed to this instruction

            grid.MoveCurrentCell(new RowColumnIndex(rowIndex, c), false);

            grid.SelectionController.CurrentCellManager.BeginEdit();

            //Is there a difference between the instruction above and the one below?

    //manager.BeginEdit();

            return;

        }

    }


    var sameCell = new RowColumnIndex(rowIndex, colIndex);

    grid.MoveCurrentCell(sameCell, false);

    grid.SelectionController.CurrentCellManager.BeginEdit();

    return;

}


Thanks for the help




1 Reply

RM Rabina Murugan Syncfusion Team May 21, 2025 03:31 PM UTC

Hi Hugo Ruiz,


We have investigated the reported scenario and reviewed the code you provided. In our earlier response, we shared a sample that achieved your requirement by overriding the GridSelectionController and handling the current cell movement accordingly in the ProcessKeyDown event.


However, we noticed that you are now handling the current cell movement in the DataGrid's PreviewKeyDown event instead. Could you please clarify your intention for using the PreviewKeyDown event in this context?


This information will help us analyze and provide a precise solution.


Regards,

Rabina


Loader.
Up arrow icon