Tecla [Enter] como [Tab] en un DataGridView

En estos últimos días, he tenido un problema que me ha traido de cabeza: ¿Cómo hago para utilizar la tecla Enter como Tab dentro de un DataGridView en .NET 2.0?

Ayer estuve en la CodeCamp en Madrid junto a expertos (MVP, MVS, empleados de Microsoft, …) y al fin me dieron una aproximación a la solución. Ver aproximación a la solución.

Más tarde, haciendo un poco de estudio, encontré una solución mejor a mi juicio y aquí os la dejo. Conste que jamás podría haber sido encontrada si no me hubiera echado este cable el amigo Pep.

using System;
using System.Windows.Forms;
using System.Text;

namespace Utilidades
{
    public class DataGridViewEx : DataGridView
    {
        ///Convierte [Enter] a [Tab] cuando estamos en modo edición.
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                SendKeys.Send("{tab}");
                return true;
            }
        else
            return base.ProcessDialogKey(keyData);
        }

        ///Convierte [Enter] a [Tab] en modo normal.
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                SendKeys.Send("{tab}");
            }
            else
            base.OnKeyDown(e);
        }
    }
}

Advertisement

1 Response to “Tecla [Enter] como [Tab] en un DataGridView”


  1. 1 siliomario 16 April 2007 at 20:52

    Muchachos entiendo todo lo que hicieron, pero tengo una pregunta.

    ¿Donde pego este codigo? y como agrego el control al toolbox


Comments are currently closed.



About me


My name is Rafa Vargas. I'm an undergraduate student of Computer Science at University of Seville, Spain. I am mainly interested in computer security, usability and the business of software.

Click here to read the full story.

Twitter subscription

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 6 other followers

Archives


Follow

Get every new post delivered to your Inbox.