Error passing parameters from the grid view of a form in the combo box

2

Good morning, I have a form where I consult my budgets and in it I have 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 the first item in my combo appears.

This is the event and code that 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 what 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;    
}
    
asked by anonymous 19.12.2016 / 13:27

1 answer

0

Since it is in the event CellContentDoubleClick replace dgvOrc.SelectedRows[0] with 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;
    
19.12.2016 / 14:26