I need to fill out a datagridview with more than 7,000 records that I get through a method that returns a generic list of objects. My problem is that when I assign it to datagriview.DataSource = LN.ObtainAll () positions; through the load method of the Form, it is fried and blocks the complete application for about 30 seconds and after that, the grid is filled and everything is fine!.
1- How to implement a progress bar using async and await ?, to inform the user of the progress of that task.
Note: I use programming in 3 layers, the Form is in a project that belongs to the presentation layer, which is communicated to the data access layer through the business layer. (Visual Studio 2015, C # and MySql).
// Proyecto Entidades:
public sealed class Posicion
{
public int IdPosicion { get; set; }
public Fila Fila { get; set; }
public int Numero { get; set; }
public string NombreCompleto => string.Format(CultureInfo.CurrentCulture, "{0} - {1}", Fila.NombreCompleto, Numero);
}
// Proyecto AccesoDatos: PosicionAD.cs
public static List<Posicion> ObtenerTodos()
{
var lista = new List<Posicion>();
const string sql = @"spu_posicion_obtenertodos";
using (var lector = helper.ExecuteReader(CommandType.StoredProcedure, sql))
{
while (lector.Read())
{
lista.Add(CargarPosicion(lector));
}
return lista;
}
}
private static Posicion CargarPosicion(IDataReader dr)
{
var ordinalIdPosicion = dr.GetOrdinal("idposicion");
var ordinalIdFila = dr.GetOrdinal("id_Fila");
var ordinalNumero = dr.GetOrdinal("numero");
var colCount = dr.FieldCount;
var values = new object[colCount];
var objPosicion = new Posicion();
dr.GetValues(values);
objPosicion.IdPosicion = Convert.ToInt32(values[ordinalIdPosicion]);
objPosicion.Fila = FilaAD.ObtenerPorId(Convert.ToInt32(values[ordinalIdFila]));
objPosicion.Numero = Convert.ToInt32(values[ordinalNumero]);
return objPosicion;
}
// Proyecto LogicaNegocio: PosicionLN.cs
public static List<Posicion> ObtenerTodos()
{
return PosicionAD.ObtenerTodos();
}
// Proyecto Presentacion: FrmPosicion.cs
private void FrmPosicion_Load(object sender, EventArgs e)
{
dgvDatosPosicion.AutoGenerateColumns = false;
dgvDatosPosicion.DataSource = PosicionLN.ObtenerTodos();
}