DataGridView中当单元格处于编辑状态下,按回车键,通常焦点会移到下一行去(末行除外).
怎样设置才能使按了回车以后停留在刚才编辑的那行.
注意是单元格编辑状态下
我想在某单元格上录一信息然后检索数据库带出一系列信息但是发现单元格在录数据时变成编辑状态。然后录入完毕敲回车,他竟然都没有响应DataGridView的KeyDown事件。。要退出编辑状态在上面回车才会响应
哥哥些。要怎么处理喃,,能否详细说明。最好是能回画退出编辑状态然后能响应到回车事件。。
private void sgPersons_KeyDown(object sender, KeyEventArgs e)
{ if (sgPersons.Rows.Count > 0)
{
if (e.KeyValue == 13)
{
//e.Handled = true;
if (sgPersons.CurrentCell.ColumnIndex == 0) //是否是工单编号列
{ string sql;
try
{
string ss = sgPersons.CurrentRow.Cells[0].Value.ToString(); sql = "SELECT WoCode,WoGoods,GoodsBCode=isnull((Select GoodsBCode from sdGoods where GoodsCode=WoGoods),''), WoGoodsName=isNull((SELECT GoodsName+GoodsSpec FROM sdGoods WHERE GoodsCode=WoGoods),''),";
sql += "WoLianShu,WoPaper='' FROM sdWo where WoCode = '" + ss + "'";
SqlDataReader reads = MySQL.ExecuteReader(sql); if (reads.HasRows)
{
while (reads.Read())
{
sgPersons.Rows[sgPersons.CurrentCell.RowIndex].Cells[1].Value = reads["GoodsBCode"].ToString();
sgPersons.Rows[sgPersons.CurrentCell.RowIndex].Cells[2].Value = reads["WoGoodsName"].ToString();
sgPersons.Rows[sgPersons.CurrentCell.RowIndex].Cells[6].Value = reads["WoGoods"].ToString(); } }
else
{
MessageBox.Show("该工单号不存在,请重新输入!"); }
reads.Close();
}
catch
{ }
}
}
}
}
怎样设置才能使按了回车以后停留在刚才编辑的那行.
注意是单元格编辑状态下
我想在某单元格上录一信息然后检索数据库带出一系列信息但是发现单元格在录数据时变成编辑状态。然后录入完毕敲回车,他竟然都没有响应DataGridView的KeyDown事件。。要退出编辑状态在上面回车才会响应
哥哥些。要怎么处理喃,,能否详细说明。最好是能回画退出编辑状态然后能响应到回车事件。。
private void sgPersons_KeyDown(object sender, KeyEventArgs e)
{ if (sgPersons.Rows.Count > 0)
{
if (e.KeyValue == 13)
{
//e.Handled = true;
if (sgPersons.CurrentCell.ColumnIndex == 0) //是否是工单编号列
{ string sql;
try
{
string ss = sgPersons.CurrentRow.Cells[0].Value.ToString(); sql = "SELECT WoCode,WoGoods,GoodsBCode=isnull((Select GoodsBCode from sdGoods where GoodsCode=WoGoods),''), WoGoodsName=isNull((SELECT GoodsName+GoodsSpec FROM sdGoods WHERE GoodsCode=WoGoods),''),";
sql += "WoLianShu,WoPaper='' FROM sdWo where WoCode = '" + ss + "'";
SqlDataReader reads = MySQL.ExecuteReader(sql); if (reads.HasRows)
{
while (reads.Read())
{
sgPersons.Rows[sgPersons.CurrentCell.RowIndex].Cells[1].Value = reads["GoodsBCode"].ToString();
sgPersons.Rows[sgPersons.CurrentCell.RowIndex].Cells[2].Value = reads["WoGoodsName"].ToString();
sgPersons.Rows[sgPersons.CurrentCell.RowIndex].Cells[6].Value = reads["WoGoods"].ToString(); } }
else
{
MessageBox.Show("该工单号不存在,请重新输入!"); }
reads.Close();
}
catch
{ }
}
}
}
}
{
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))
{
base.CurrentCell = base.Rows[base.RowCount - 1].Cells[0];
return true;
}
if ((base.CurrentCell.ColumnIndex == (base.ColumnCount - 1)) && (base.CurrentCell.RowIndex < (base.RowCount - 1)))
{
base.CurrentCell = base.Rows[base.CurrentCell.RowIndex + 1].Cells[0];
return true;
} return base.ProcessRightKey(keyData);
}
return base.ProcessRightKey(keyData);
}
}