DataGridView单元格问题 在某一单元格内,怎么按回车后跳到同行的下一单元格,而不是跳到这个单元格同列的单元格里?试了几种方法,在很多事件里实现总容易出现 SetCurrentCellAddressCore 错误。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 JS可以实现啊。。 if (event.which || event.keyCode) { if ((event.which == 13) || (event.keyCode == 13)) { document.getElementById('objectID').focus(); event.returnValue = false; event.cancel = true; return false; } } else { return true; } 重载一个方法试一试: protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData){ switch (keyData) { case System.Windows.Forms.Keys.Enter: { System.Windows.Forms.SendKeys.Send("{TAB}"); return true; } return base.ProcessCmdKey(ref msg, keyData); }} private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { //for(int i=0;i<dataGridView1.Rows.Count-1;i++) //{ // this.dataGridView1.Rows[i].Cells[0].Value = e.RowIndex; //} //int i = 0; //for (i = K; i < dataGridView1.Rows.Count - 1; i++) //{ // this.dataGridView1.Rows[i].Cells[0].Value = dataGridView1.Rows.Count - 1; //} //K++; } private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { //for(int i=0;i<dataGridView1.Rows.Count-1;i++) //{ // this.dataGridView1.Rows[i].Cells[0].Value = e.RowIndex; //} //int i = 0; //for (i = K; i < dataGridView1.Rows.Count - 1; i++) //{ // this.dataGridView1.Rows[i].Cells[0].Value = dataGridView1.Rows.Count - 1; //} //K++; } 响应按键事件,再定位表的rowindex 在键盘的keydown事件下写,获取当前单元格,然后选中下一个单元格,状态附成edit 首先在vs的view菜单栏设置taborder项,排好顺序以后在控件的这个事件里面写下这个代码就ok了。#region 自定义函数 /// <summary> /// 共通的ENTER处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Control_KeyPress(object sender, KeyPressEventArgs e) { OpenFileDialog op = new OpenFileDialog(); if (e.KeyChar == (Char)(Keys.Enter)) { if (sender is TextBoxBase && ((TextBoxBase)sender).Name == "txtItemCD") { if (!itemCheck()) { txtItemCD.SelectAll(); return; } } else { this.SelectNextControl(this.ActiveControl, true, true, true, true); if (this.ActiveControl is Button && this.ActiveControl.Tag.ToString() == "stop") { this.SelectNextControl(this.ActiveControl, true, true, true, true); } } } } 用C# 在win7下能像在XP下正常读取注册表的值吗?在线等 跪求C#的CRC校验计算方法!!!!![串口通信] 成本核算 系统 datagridview 下拉列表 关于PictureBox显示大红叉问题-----最新修改+源码;还是有问题,请高手亮剑吧!!!!!!!!!! 有关部署安装的问题,比较急 辞职前的最后3个问题之一单例模式, dropdownlist的问题 在位置 2 处没有任何行 dataset的问题??? C# 特殊字符 存入SQLITE数据库中! directshow和线程的问题 咬文嚼字的问题!Array.Length和int length=Array.Length
if (event.which || event.keyCode) {
if ((event.which == 13) || (event.keyCode == 13)) {
document.getElementById('objectID').focus();
event.returnValue = false;
event.cancel = true;
return false;
}
}
else { return true; }
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
switch (keyData)
{
case System.Windows.Forms.Keys.Enter:
{
System.Windows.Forms.SendKeys.Send("{TAB}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
{
//for(int i=0;i<dataGridView1.Rows.Count-1;i++)
//{
// this.dataGridView1.Rows[i].Cells[0].Value = e.RowIndex;
//}
//int i = 0; //for (i = K; i < dataGridView1.Rows.Count - 1; i++)
//{
// this.dataGridView1.Rows[i].Cells[0].Value = dataGridView1.Rows.Count - 1;
//}
//K++;
}
{
//for(int i=0;i<dataGridView1.Rows.Count-1;i++)
//{
// this.dataGridView1.Rows[i].Cells[0].Value = e.RowIndex;
//}
//int i = 0; //for (i = K; i < dataGridView1.Rows.Count - 1; i++)
//{
// this.dataGridView1.Rows[i].Cells[0].Value = dataGridView1.Rows.Count - 1;
//}
//K++;
}
在控件的这个事件里面写下这个代码就ok了。
#region 自定义函数
/// <summary>
/// 共通的ENTER处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Control_KeyPress(object sender, KeyPressEventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
if (e.KeyChar == (Char)(Keys.Enter))
{ if (sender is TextBoxBase && ((TextBoxBase)sender).Name == "txtItemCD")
{
if (!itemCheck())
{
txtItemCD.SelectAll();
return;
}
}
else
{
this.SelectNextControl(this.ActiveControl, true, true, true, true);
if (this.ActiveControl is Button && this.ActiveControl.Tag.ToString() == "stop")
{
this.SelectNextControl(this.ActiveControl, true, true, true, true);
}
}
}
}