C# 如何将焦点放回上次编辑的单元格?
我正在保存绑定的datagridview,在事件中,我正在使用以下方法保存记录:C# 如何将焦点放回上次编辑的单元格?,c#,datagridview,.net-4.0,C#,Datagridview,.net 4.0,我正在保存绑定的datagridview,在事件中,我正在使用以下方法保存记录: void dataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e) { try { Entity.SaveChanges(); } catch (Exception ex) { MessageBox.Show(string.Format("Error while saving. Check the c
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
}
}