winfrom中datagridview如何使用TAB键切换行 rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void dataGridView1_KeyDown(object sender, KeyEventArgs e){ if (dataGridView1.CurrentRow.Index >= dataGridView1.RowCount) return; if (e.KeyCode == Keys.Tab) { DataGridViewCell cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1]; dataGridView1.CurrentCell = cell; e.Handled = true; }} 从DataGridView派生一个新类,在新类中覆盖ProcessDialogKey方法protected override bool ProcessDialogKey(Keys keyData) { if (key == Keys.Tab) { base.CurrentRow = base.Rows[base.CurrentRow.Index + 1]; return true; } return base.ProcessDialogKey(keyData); } 以上两种方法看似都可行,不过我没去试提醒一下就是:Index + 1时先检查一下看是不是最后一行了. protected override bool ProcessCmdKey(ref Message msg, Keys KeyData) { if (KeyData == Keys.tab) { SendKeys.Send("{Enter}"); return true; } return base.ProcessCmdKey(ref msg, KeyData); } private void dataGridView1_KeyDown(object sender, KeyEventArgs e){ if (e.KeyCode == Keys.Tab) { SendKeys.Send("{Enter}"); e.Handled = true; }} 你好,你的方法可行,偷梁换柱了一下,你是想按TAB时是想ENTER的功能,但是我按ENTER时,又触发了另外 一个事件,所以此方法不可行, 改为dataGridView1.CurrentRow.Index>= dataGridView1.RowCount-1 你好,结果是正确的,但是如何能完善一下呢:就是能用TAB和SHIF+TAB进行各条记录之间切换,目前第一行切换不到,而且最后一行不是记录间切换,而是最后一行单元格间切换,我想要整条切换,如何实现,谢谢! if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Tab && e.Shift == true){ DataGridViewCell cell; if (dataGridView1.CurrentRow.Index < dataGridView1.RowCount - 1) cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1]; else cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, 0]; dataGridView1.CurrentCell = cell; e.Handled = true;} private void dataGridView1_KeyDown(object sender, KeyEventArgs e){ // 13楼代码} c# WebBrowser如何去掉最大化按钮 请教一个图片封装dll的问题 求大虾来帮忙! 编写手机发短信问题【100】 C# winform中实现控件缩放 c#界面美化 关于PictrueBox,背景透明问题,多个筹码叠加效果.急.... 关于图片下载的问题,为什么图片下载后会出现在程序运行的目录下面????? 如何知道一个软件是否在本机安装 有谁知道这个Expression怎么写? 如何提高自己的技术水平 求水晶报表循环显示数据(具体看内容)急
{
if (dataGridView1.CurrentRow.Index >= dataGridView1.RowCount) return;
if (e.KeyCode == Keys.Tab)
{
DataGridViewCell cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1];
dataGridView1.CurrentCell = cell;
e.Handled = true;
}
}
{
if (key == Keys.Tab)
{
base.CurrentRow = base.Rows[base.CurrentRow.Index + 1];
return true;
}
return base.ProcessDialogKey(keyData);
}
提醒一下就是:Index + 1时先检查一下看是不是最后一行了.
{
if (KeyData == Keys.tab)
{
SendKeys.Send("{Enter}");
return true;
}
return base.ProcessCmdKey(ref msg, KeyData);
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
SendKeys.Send("{Enter}");
e.Handled = true;
}
}
你好,你的方法可行,偷梁换柱了一下,你是想按TAB时是想ENTER的功能,但是我按ENTER时,又触发了另外 一个事件,所以此方法不可行,
改为
dataGridView1.CurrentRow.Index>= dataGridView1.RowCount-1
你好,结果是正确的,但是如何能完善一下呢:
就是能用TAB和SHIF+TAB进行各条记录之间切换,目前第一行切换不到,而且最后一行不是记录间切换,而是最后一行单元格间切换,我想要整条切换,如何实现,谢谢!
{
DataGridViewCell cell;
if (dataGridView1.CurrentRow.Index < dataGridView1.RowCount - 1)
cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1];
else cell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, 0];
dataGridView1.CurrentCell = cell;
e.Handled = true;
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
// 13楼代码
}