C# :DataGridView中使按下Enter键达到与按下Tab键一样的效果?

代码

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class myDataGridView : DataGridView

{

    protected override bool ProcessDialogKey(Keys keyData)

    {

        if (keyData == Keys.Enter)

        {

            int col = this.CurrentCell.ColumnIndex;

            int row = this.CurrentCell.RowIndex;

            if (row != this.NewRowIndex)

            {

                if (col == (this.Columns.Count - 1))

                {

                    col = -1;

                    row++;

                }

                this.CurrentCell = this[col + 1, row];

            }

            return true;

        }

        return base.ProcessDialogKey(keyData);

    }

 

    protected override void OnKeyDown(KeyEventArgs e)

    {

        if (e.KeyData == Keys.Enter)

        {

            int col = this.CurrentCell.ColumnIndex;

            int row = this.CurrentCell.RowIndex;

            if (row != this.NewRowIndex)

            {

                if (col == (this.Columns.Count - 1))

                {

                    col = -1;

                    row++;

                }

                this.CurrentCell = this[col + 1, row];

            }

            e.Handled = true;

        }

        base.OnKeyDown(e);

    }

}

 

posted @ 2014-02-19 13:26  Net-Spider  阅读(246)  评论(0)    收藏  举报