我如何把焦点放在最后一个单元格编辑
本文关键字:最后一个 单元格 编辑 焦点 | 更新日期: 2023-09-27 18:16:29
我正在保存我的绑定datagridview和事件,我用这个方法保存记录:
void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
{
try
{
Entity.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error while saving. Check the current row for errors.{0}{0}Exception:{0}{0}{1}", Environment.NewLine, ex.Message));
// I'd like to push it back to the last cell edited here
}
}
如果发生异常,我想将用户焦点推回到最后编辑的单元格。这可能吗?
有办法做到这一点吗?
string tbname;
void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
{
try
{
Entity.SaveChanges();
tbname = Entity.Accessible.Name; //save the name of the last edit textbox
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error while saving. Check the current row for errors.{0}{0}Exception:{0}{0}{1}", Environment.NewLine, ex.Message));
tbname.focus(); //will return the focus to that textbox last edited
}
}