Haber trata con el keyDown
Código c#:
Ver originalprivate void txtNit_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (txtNit.Text != "")
{
for (int i = 0; i < dgvPersonas.Rows.Count; i++)
{
if (dgvPersonas.Rows[i].Cells[0].Value != null)
{
if (dgvPersonas.Rows[i].Cells[0].Value.ToString() == txtNit.Text.ToString())
{
MessageBox.Show("El nit introducido ya existe", "..Datos Repetidos..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
i = dgvPersonas.Rows.Count;
sw = 1;
limpiar();
}
}
}
}
}
}
Si presionas enter lo invocas. Verifica que en las propiedades de tu Form este como
true keypreview