Problem with Textbox Update c#

Asked

Viewed 131 times

0

Have:

  • 2 Radiobutton
  • 1 Combobox
  • 1 Textbox

The value of radiobutton chosen goes to the TextBox plus the value of Combobox.

TextBox = RadioButton + Combobox

But if I change, the value of Radiobutton, the Textbox does not change, is changing the value of Textbox if you change Radiobutton or Combobox.

Code:

  private void combobox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (radiobutton1.Checked && combobox1.Text == "Cerfificação (CER)")
        {
            textbox1.Text = "CER" + " SRV";
        }
        if (radiobutton1.Checked && combobox1.Text == "Desenvolvimento (DES)")
        {
            textbox1.Text = "DES" + " SRV";
        }
        if (radiobutton2.Checked && combobox1.Text == "Desenvolvimento (DES)")
        {
            textbox1.Text = "DES" + " CLI";
        }

1 answer

1


I made a quick example here:

private void cmb1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // Converte o item selecionado em um item do combobox
    ComboBoxItem item = (ComboBoxItem)cmb1.SelectedItem;
    // assim consigo pegar o valor dele
    string valor = item.Content.ToString();
//chk1 = radionButton ou CheckBox
// (chk1.IsChecked ?? false) pega o valor que seja diferente de false. pois o CheckBox possui 3 estados.

// faço a comparação se o checkbox está selecionado com o valor que foi selecionado.
if ((radio1.IsChecked ?? false) && valor.Equals("Valor 1"))
    txt1.Text = radio1.Content + valor;

else if ((radio1.IsChecked ?? false) && valor.Equals("Valor 2"))
    txt1.Text = radio1.Content + valor;

else if ((radio2.IsChecked ?? false) && valor.Equals("Valor 3"))
     txt1.Text = radio2.Content + valor;
}
  • No friend @Meuchapeu, so don’t give me...

  • Why? Some mistake happens?

  • @Godfathersantana, I made a change to the code, so it’s only working when you change it to combobox if you want to change when you change RadioButton will need to have an event of Checked in the RadioButton to change when a change is made to RadioButton.

  • Friend @Meuchapeu, I need both, IE when it changes RadioButton and Combobox.

  • @Godfathersantana, Yes only implements the event Checked of RadioButton and validate (IFs) no event. as was done in the event of ComboBox when the selection is changed.

  • 1

    Already got it, thanks friend @Meuchapeu!

Show 1 more comment

Browser other questions tagged

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