Click here to Skip to main content
15,905,068 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys

please help me on thing...
cause i want to select a record in the datagrid using a keydown event
when i press [ENTER] key.
i just don't know how to get the values in the datagrid columns

please help me...
thanks in advance...
Posted
Comments
Member 3279003 16-Jan-12 1:10am    
I need how i could this in vb 6. When i press key down or up whole row select like msflexgrid.

1 solution

This should point you in the right direction.

C#
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
  if (e.KeyCode.Equals(Keys.Enter))
  {
    DataGridViewRow dgr = dataGridView1.CurrentRow;
    string column0 = dgr.Cells[0].Value.ToString();
  }
}

Also, don't forget that unless you don't do anything else, once the KeyDown event has finished, then the current row will move on one - my code snippet correctly captures the current row before the cursor moves.
 
Share this answer
 
v2
Comments
RaviRanjanKr 12-Jul-11 9:42am    
Nice Answer, My 5.
yogesh vaidya 24-Nov-17 14:30pm    
how to do this in visual basic 2013 or 2014 ,i am not working in c++
please help me to solve this (appajis72@gmail.com)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900