在寫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;
    }

        }

arrow
arrow
    全站熱搜

    丫德 發表在 痞客邦 留言(1) 人氣()