Indusrilanka
Indusrilanka

Reputation: 1

How to capture enter key in DataGridView CellContentClick

How to capture the enter key in DataGridView.CellContentClick in c#

Upvotes: 0

Views: 2748

Answers (1)

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

only the spacebar is handled, so you have to capture the KeyUp event on the cell first and raise the CellContentClick if you want that.

private void cell_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
    {
        // modify/cast/transform e here to DataGridViewCellEventArgs
        dataGridView_CellContentClick(sender, e) 
    }
}

Upvotes: 1

Related Questions