Pull data from Datagridview to a form

Asked

Viewed 36 times

0

I got a problem where I got two forms TelaInicio and ExibirDados and I’m trying to make sure that when the user double-click on some line in the Grid will open a form pulling the information relating to that line.

First I’m instantiating the form ExibirDados in TelaInicio

 public partial class TelaInicio : MetroFramework.Forms.MetroForm
 {

    internal ExibirDados exibirdados = null;

    public TelaInicio(ExibirDados exibirdados)
    {
        InitializeComponent();
        this.exibirdados = exibirdados;
    }

And when giving Double Click on Grid I run this code:

  private void dgvDados_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
  {
        if (dgvDados.SelectedRows.Count > 0)
        {
            this.exibirdados.txtcnpj.Text = dgvDados.SelectedRows[0].Cells[0].Value.ToString();
            this.exibirdados.dtpcadastro.Text = dgvDados.CurrentRow.Cells[1].Value.ToString();
            this.exibirdados.txtrazao.Text = dgvDados.CurrentRow.Cells[2].Value.ToString();
            this.exibirdados.cmboperadora.Text = dgvDados.CurrentRow.Cells[3].Value.ToString();
            this.exibirdados.txtlinhas.Text = dgvDados.CurrentRow.Cells[4].Value.ToString();
            this.exibirdados.cmbClassificacao.Text = dgvDados.CurrentRow.Cells[5].Value.ToString();
            this.exibirdados.dtpvigencia.Text = dgvDados.CurrentRow.Cells[6].Value.ToString();
            this.exibirdados.txtcontrato.Text = dgvDados.CurrentRow.Cells[7].Value.ToString();
            this.exibirdados.cmbFidelidade.Text = dgvDados.CurrentRow.Cells[8].Value.ToString();
            this.exibirdados.txtvalorgasto.Text = dgvDados.CurrentRow.Cells[9].Value.ToString();
            this.exibirdados.txtfixoempresa.Text = dgvDados.CurrentRow.Cells[10].Value.ToString();
            this.exibirdados.txtgestor.Text = dgvDados.CurrentRow.Cells[11].Value.ToString();
            this.exibirdados.txtcelular.Text = dgvDados.CurrentRow.Cells[12].Value.ToString();
            this.exibirdados.txtfixogestor.Text = dgvDados.CurrentRow.Cells[13].Value.ToString();
            this.exibirdados.txtemail.Text = dgvDados.CurrentRow.Cells[14].Value.ToString();
            this.exibirdados.txtobs.Text = dgvDados.CurrentRow.Cells[15].Value.ToString();
        }

        ExibirDados form = new ExibirDados();
        form.ShowDialog();
    }

With this code he even opens the form but does not pull any information to the fields, the amount of fields is right and in my case the primary key is the CNPJ.

1 answer

2


You are assigning the values to the form this.exibirdados, but is instantiating a new ExibirDados and displaying this newly created.

Change this:

ExibirDados form = new ExibirDados();
form.ShowDialog();

That’s why:

this.exibirdados.ShowDialog();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.