Gold
Gold

Reputation: 62464

How to pick row from DataGridView?

how i can move on rows in DataGridView and when i press [Enter]

i'll get the value of the data in colum - 0 and the row that i stand on hem ?

(when i press [Enter] the cursor move to row+1 and i dont whant this - only this

that i stand on him)

thank's

Upvotes: 1

Views: 585

Answers (1)

hawbsl
hawbsl

Reputation: 16003

The DataGridView has a CurrentRow property.

Handle the KeyDown event for the DataGridView to capture the ENTER key. Set e.Handled to true to stop the ENTER key's default behaviour.

To get the data in column 0 check the CurrentRow.Cells(0).Value.

Sample:

    private void MyGrid_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Enter)
        {
            e.Handled = true;
            DataGridViewRow currentRow = MyGrid.CurrentRow;
            MessageBox.Show( Convert.ToString(currentRow.Cells[0].Value));
        }
    }

Upvotes: 2

Related Questions