This is a migrated thread and some comments may be shown as answers.

Close Editor After Cell Edit

4 Answers 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 16 Jun 2016, 09:08 PM
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?

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 17 Jun 2016, 07:13 AM
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.
0
Kyle
Top achievements
Rank 1
answered on 17 Jun 2016, 03:21 PM

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?

0
Accepted
Dimitar
Telerik team
answered on 20 Jun 2016, 05:43 AM
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.
0
Kyle
Top achievements
Rank 1
answered on 20 Jun 2016, 02:51 PM
Thank you. That did the trick.
Tags
GridView
Asked by
Kyle
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Kyle
Top achievements
Rank 1
Share this question
or