Load from a DataGridView different forms with the same fields but different characteristics


I have different forms with the same fields but with different characteristics.

I want to load the corresponding form from a DataGridView depending on the values of txtTransport and txtType.

My code is as follows:

    private void dgvConsultas_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        var transporte = dgvConsultas.CurrentRow.Cells[3].Value.ToString();
        var tipo = dgvConsultas.CurrentRow.Cells[4].Value.ToString();

        if (transporte == "A" && tipo == "E")
            frmCotizacionesAE form = new frmCotizacionesAE();

        if (transporte == "A" && tipo == "I")
            frmCotizacionesAI form = new frmCotizacionesAI();

        form.lblReferencia.Text = dgvConsultas.CurrentRow.Cells[0].Value.ToString();
        form.lblEstado.Text = dgvConsultas.CurrentRow.Cells[1].Value.ToString();
        form.lblAnno.Text = dgvConsultas.CurrentRow.Cells[2].Value.ToString();
        form.lblTransporte.Text = dgvConsultas.CurrentRow.Cells[3].Value.ToString();
        form.lblTipo.Text = dgvConsultas.CurrentRow.Cells[4].Value.ToString();
        form.txtCliente.Text = dgvConsultas.CurrentRow.Cells[5].Value.ToString();
        form.txtContacto.Text = dgvConsultas.CurrentRow.Cells[6].Value.ToString();
    // --- más campos ---
        form.txtSeguroV.Text = dgvConsultas.CurrentRow.Cells[44].Value.ToString();
        form.txtSeguroC.Text = dgvConsultas.CurrentRow.Cells[45].Value.ToString();
        form.txtValidez.Text = dgvConsultas.CurrentRow.Cells[46].Value.ToString();


Error when using "form" for both forms. I have 11 similar forms (with 47 fields each) and I do not want to repeat the code using: form, form1, form2, etc. for each form.

I will appreciate your kind help.

Thank you very much and regards.


asked by Ricardo Zevallos 21.11.2018 в 21:23

0 answers