当目前的CurrentRow不存在时的判断
在写winform时,要判断当目前的datagridview中,使用者在新增模式时
在button栏位中按下空白键,但目前该列是没有值的,因此得不到目前row中的某个cell的值
因此想要跳过目前这个栏位直接切换到下一栏时,那么可以用以下的语法
private void dg_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
switch (e.ColumnIndex)
{
case 1:
if (this.dg.CurrentRow == null)
{
this.dg.CurrentCell = this.dg.Rows[e.RowIndex].Cells["xxx"];
this.dg.Focus();
}
else
this.DeleteRow(this.dg.CurrentRow.Index);
break;
}
}