Close Editor After Cell Edit

5 posts, 1 answers
  1. Kyle
    Kyle avatar
    3 posts
    Member since:
    Sep 2015

    Posted 16 Jun Link to this post

    When I edit a cell then move to another cell the editor is opened for the moved to cell. How do I change this behavior so the editor does not open when moving to a new cell?
  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 17 Jun Link to this post

    Hello Kyle,

    Thank you for writing.

    You should create custom grid navigator and override the SelectCore method:
    class MyBaseGridNavigator : BaseGridNavigator
    {
        protected override bool SelectCore(GridViewRowInfo row, GridViewColumn column)
        {
            this.GridViewElement.EndEdit();
            return  base.SelectCore(row, column);
        }
    }

    You can change the default navigator like this:
    radGridView1.GridViewElement.Navigator = new MyBaseGridNavigator();

    Let me know if I can assist you further.

    Regards,
    Dimitar
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kyle
    Kyle avatar
    3 posts
    Member since:
    Sep 2015

    Posted 17 Jun in reply to Dimitar Link to this post

    Thanks for your response.

    Your code worked when I'm editing a cell and use the arrow keys, but when I edit a cell and hit the enter key it moves to the cell below and puts it in edit mode.

    Any ideas?

  5. Answer
    Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 20 Jun Link to this post

    Hi Kyle,

    Thank you for writing back.

    To handle the Enter key you need to create a custom row behavior and override the ProcessEnterKey method. The following snippet shows this along with how you can register the new behavior:
    public Form1()
    {
        InitializeComponent();
     
        BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
        gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
        gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridRowBehavior());
    }
     
    class CustomGridRowBehavior : GridDataRowBehavior
    {
        protected override bool ProcessEnterKey(KeyEventArgs keys)
        {
            var result = base.ProcessEnterKey(keys);
            this.GridControl.EndEdit();
            return result;
        }
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  6. Kyle
    Kyle avatar
    3 posts
    Member since:
    Sep 2015

    Posted 20 Jun in reply to Dimitar Link to this post

    Thank you. That did the trick.
Back to Top
UI for WinForms is Visual Studio 2017 Ready