Pass Combobox Value to Parameter

Asked

Viewed 473 times

0

I am developing a solution in C# Windows Forms and I’m having doubts about how to take one of my combo box options that is activated when a checked is clicked. This Combo has the option of yes and no, but when I pass it to the parameter the value comes blank.

if (chbSim.Checked)
{
    txtValor.Enabled = false;
    cmBSimNao.Enabled = true;
    param.Valor = cmBSimNao.Text;
    param.Nome = this.txtNome.Text;
    param.Descricao = this.txtDescricao.Text;
}

1 answer

0


You should use the replace the excerpt below:


    param.Valor = cmBSimNao.Text;

For


   param.Valor = cmBSimNao.SelectedItem.ToString();

Selectedit property obtains or defines the selected item.

See reference: Property Combobox.Selectedit

  • I tried to do this, but the Value parameter is string, how can I convert?

  • cmBSimNao.SelectedItem.ToString()

  • That’s what @Brunoh. said. I edited the answer.

  • I did it and it worked. W!

Browser other questions tagged

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