pavan
pavan

Reputation: 149

raise event on pressing enter in datagridview cells

I want to get the value of the first cell of a row in the datagridview on selecting any cell of the row of the datagridview and pressing enter. How to do it?

Upvotes: 0

Views: 1461

Answers (1)

mao
mao

Reputation: 1404

You may handle DataGridView.KeyDown event. For example:

    object firstCellValue = null;
    private void dgv_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Enter)
        {
            firstCellValue = dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value;
        }
    }

Upvotes: 1

Related Questions