Assign data to a DataGridView

0

Hi, I am trying to assign data to a DataGridView by means of a list, but I only manage to pass data to it once, but I need that when adding several records to the list I will load all those assigned to the list and assign the list to the DGV.

var p = new Persona()
        {
            Id = Utilidades.RowId,
            Nombre = Utilidades.RowDes
        };

        listPersona.Add(p);

        foreach (DataGridViewRow row in dgvPersona.Rows)
        {
            foreach (var item in listPersona)
            {
                row.Cells["ColCodigo"].Value = item.Id;
                row.Cells["ColName"].Value = item.Nombre;
            }
        }
    
asked by Pedro Ávila 05.11.2016 в 01:06
source

1 answer

0

I solved it in the following way.

var p = new Persona()
        {
            Id = Utilidades.RowId,
            Nombre = Utilidades.RowDes
        };

        gcPrueba3.DataSource = null;
        listPersona.Add(p);
        gcPrueba3.DataSource = listPersona;
    
answered by 05.11.2016 в 03:11