Pass data from a Datagridview in a Form to Combobox in another Form

Asked

Viewed 66 times

0

good I am with problem that two days ago I can not solve , good I will explain:

1 - I have a datagridview with the database information.

2 - this information by clicking on the line of datagridview it opens another form with the fields of text and a combobox.

3 - When clicking it will pass all the information of the datagridview to the compo text and combobox , only that the combobox she doesn’t pull the right information.

4 - need help please can help , I am more than two days looking for a solution and can not find

code:

 private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
        FrmCadastroCadBairro frmb = new FrmCadastroCadBairro();
        //AO CLICAR NA LINHA CHAMA OS DADOS DO BANCO DE DADOS
        frmb.txtcodigo.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
        frmb.cbbcidade.SelectedValue = dataGridView1.CurrentRow.Cells[1].Value.ToString();
        frmb.txtbairro.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
        //COLOCA O BOTÃO ADD  EM DISABLE
        frmb.alterabotoes(2);
        //E ABRE A JENELA
        frmb.ShowDialog();
 }

1 answer

1


The Code below should solve your problem

  frmb.cbbcidade.SelectedIndex = frmb.cbbcidade.FindString(dataGridView1.CurrentRow.Cells[1].Value.ToString());

NOTE: Make sure the combo is loaded first.

  • Thanks for the help , after publishing a few minutes after I discovered the problem kkk , was why I was loading the data , when I entered another form it carried why I was not pulling the data from datagridview, but what Oce put there , tbm works obgd!

Browser other questions tagged

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