How to load a dataGridView linked to data (DataTable) that already has columns and sizes defined by code?

0

When executing the program, the DataGridView is loaded with the linked data, but after the sixth column ... which causes only the empty rows in the DataGridView to be seen ... Here goes the code:

private void CargarGridDetalle(){
    Detalle detalle = new Detalle();
    detalle.NroPedido = txtNumPedido.Text;
    try{
        dgvDetalle.Refresh();
        dgvDetalle.DataSource = detalle.ListarDetalles(); //DataTable
    }
    catch (Exception ex){
        MessageBox.Show("No se puede cargar información de PEDIDOS: " + ex.Message
            , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

private void ConfiguraGrillaDetalle() {
    dgvDetalle.ColumnCount = 6;
    dgvDetalle.Columns[0].Width = 80; dgvDetalle.Columns[0].HeaderText = "Codigo";
    dgvDetalle.Columns[1].Width = 100; dgvDetalle.Columns[1].HeaderText = "Producto";
    dgvDetalle.Columns[2].Width = 80; dgvDetalle.Columns[2].HeaderText = "Precio";
    dgvDetalle.Columns[3].Width = 50; dgvDetalle.Columns[3].HeaderText = "Cantidad";
    dgvDetalle.Columns[4].Width = 50; dgvDetalle.Columns[4].HeaderText = "Descuento";
    dgvDetalle.Columns[5].Width = 80; dgvDetalle.Columns[5].HeaderText = "Total";
}

By moving the horizontal scroll of the DataGridView, you can see the uploaded records:

    
asked by Rodrigo Valdivia 30.05.2018 в 23:40
source

0 answers