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

Don't allow to end edit mode with key left or right

2 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Josef
Top achievements
Rank 1
Josef asked on 14 Feb 2013, 07:16 AM
I'm using Winforms Q2 2011 SP1.
The gridview cell is in edit mode and the text cursor is at the right/left bound of the text editor.
How can I avoid that on the next right / left key the editor is closed an the next cell is selected.

2 Answers, 1 is accepted

Sort by
0
Accepted
Josef
Top achievements
Rank 1
answered on 18 Feb 2013, 07:47 AM
I think I found my one solution using a custom grid behavior inspired by http://www.telerik.com/community/forums/winforms/gridview/disable-arrow-keys.aspx .
I'd appreciate further comments for improvement or problematic aspects I didn't consider.


/// <summary>
/// Custum grid behaviour
/// </summary>
public class CustomGridBehaviour : BaseGridBehavior
{
    public override bool ProcessKey(KeyEventArgs keys)
    {
 
        // Avoid that the next cell is selected if the cell is in edit mode
        // and the arrow keys left or right are pressed.
        if (!GridControl.IsInEditMode)
            return base.ProcessKey(keys);
 
        switch (keys.KeyCode)
        {
            case Keys.Left:
            case Keys.Right:
                return false;
        }
 
        return base.ProcessKey(keys);
    }
}

0
Stefan
Telerik team
answered on 19 Feb 2013, 06:18 AM
Hi Josef,

Thank you for writing.

I can confirm that this is the correct way to achieve the desired behavior. Thank you for sharing.
 

All the best,
Stefan
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
GridView
Asked by
Josef
Top achievements
Rank 1
Answers by
Josef
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or