回车后移到右边单元格
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (this.dataGridView1.Focused && e.KeyCode == Keys.Enter)
{
SendKeys.Send("{Up}");
SendKeys.Send("{Tab}");
}
}
datagridview
中按回车键换列,若是最后一行最后单元格则增加一行
DataGridView
按回车换列
,
最后单元新增一行
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public class CustomDataGridView : DataGridView
{
protected override bool ProcessDialogKey(Keys keyData)
{
Keys key = (keyData & Keys.KeyCode);
if (key == Keys.Enter)
{
return this.ProcessRightKey(keyData);
}
return base.ProcessDialogKey(keyData);
}
public new bool ProcessRightKey(Keys keyData)
{
Keys key = (keyData & Keys.KeyCode);
if (key == Keys.Enter)
{
//
第一种情况:只有一行
,
且当光标移到最后一列时
,
新增一行
if
((base.CurrentCell.ColumnIndex
==
(base.ColumnCount
-
1))
&&
(base.RowCount ==1))
{
//
新增一行