DataGridView "Enter" manejo de eventos clave
Tengo un DataGridView poblado con DataTable, tengo 10 columnas. Tengo un escenario cuando me muevo de una fila a otra cuando hago clic en la tecla Enter, entonces necesito que esa fila se seleccione y necesito tener esos valores de fila.
Pero aquí cuando seleccionon-th fila luego se mueve automáticamente an + 1 Fila.
Por favor, ayúdame en esto...
En evento de carga de página:
SqlConnection con =
new SqlConnection("Data Source=.;Initial Catalog=MHS;User ID=mhs_mt;Password=@mhsinc");
DataSet ds = new System.Data.DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from MT_INVENTORY_COUNT", con);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
Entonces,
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (Char)Keys.Enter)
{
int i = dataGridView1.CurrentRow.Index;
MessageBox.Show(i.ToString());
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int i = dataGridView1.CurrentRow.Index;
MessageBox.Show(i.ToString());
}