I would like to know what method I should use in my code so that when the DataGridView is updated, the last row selected is maintained. This is the code where I updated the dgv
Here I consult and refresh the dgv
public void BuscarVisitas(DataGridView dgv, string clave)
{
using (SqlConnection conexion = Base.ObtnerCOnexion())
{
SqlCommand com = new SqlCommand(string.Format("SELECT * FROM Visitas WHERE Vendedor ='" + clave + "'"), conexion);
SqlDataReader leer = com.ExecuteReader();
int selectedIndex;
dgv.Rows.Clear();
dgv.Refresh();
}
}
Here I use an event for when I close my form the data update is done
public void NuevaVisita_FormClosed(object sender, FormClosedEventArgs e)
{
if (txtVendedor.Text == "ADM")
{
bs.ADMBuscarVisitas2(dgvVisitas);
this.tsAutorizar.Enabled = true;
}
else
{
bs.BuscarVisitas(dgvVisitas, txtVendedor.Text);
this.tsAutorizar.Enabled = false;
}
}