Error passing grid view parameters of a form in combo box

Asked

Viewed 73 times

3

Good morning, I have a form where I consult my budgets and in it I own a grid view.

When I double-click on the grid line it opens another form. But I do not see the data that is in the line of my grid view appears the first item of my combo.

This is the event and the code I use to open in the other form. This form is the query:

private void dgvOrc_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    frmOrcDomestico formOrc = new frmOrcDomestico();
    formOrc.PreencheDados(dgvOrc.SelectedRows[0].Cells[0].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[1].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[2].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[3].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[4].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[5].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[6].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[7].Value.ToString(),
    dgvOrc.SelectedRows[0].Cells[8].Value.ToString());
    formOrc.ShowDialog();
} 

This form is the one that will receive the data from the other.

public void PreencheDados(string id, string c, string p, string t, string dom, string data, string l, string d, string pg)
{
    lblId.Text = id;

    comboCliente.Text = c;

    comboProduto.Text = p;

    comboTipoProduto.Text = t;

    lblDomestico.Text = dom;

    lbld.Text = data;

    lblStatus.Text = l;

    textDescricao.Text = d;

    maskValor.Text = pg;    
}

1 answer

0

Since you’re at the event CellContentDoubleClick substitute dgvOrc.SelectedRows[0] for dgvOrc.Rows[e.RowIndex] which is sure to request the value of the clicked line.

    private void dgvOrc_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
       frmOrcDomestico formOrc = new frmOrcDomestico();
       formOrc.PreencheDados(
         dgvOrc.Rows[e.RowIndex].Cells[0].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[1].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[2].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[3].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[4].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[5].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[6].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[7].Value.ToString(),
         dgvOrc.Rows[e.RowIndex].Cells[8].Value.ToString());
   }

This line may be wrong depending on how the combobox is: comboProduto.Text = p;

Try one of these lines:

comboProduto.SelectedValue = p;

or

comboProduto.SelectedText = p;
  • I put this command, but still do not show my grid view data in my combo. Still appears the first item in the combo list

  • Already tried comboTipoProduct.Selectedvalue = p or comboTipoProduct.Selectedtext = p ? I guess that’s it then. You need to see how the Combox is configured

  • Still the same thing, I’ve already put the two modes and appears the first item in the combo list

Browser other questions tagged

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