How to empty label when selecting a different value in combobox?

0

I have a form with a combobox made up of Locations, 2 buttons (Show and Exit) and a label that shows the location in the combo and name of the corresponding locality:

What I need is, if there is a location selected as the example of the image, when changing the selection of the location, the message is emptied.

    
asked by Agu Fortini 24.05.2017 в 02:20
source

2 answers

2

I do not know if I understood it correctly, but do you want that when you select a value that is not the one that was already selected, the contents of the label will be deleted?

If so, the previous code would be worth it with a small variation

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //En esta comparación supongo que solo es el texto del combobox lo que se copia en la label
        //si es una frase tendrias que "currarte" la comparación(muy facil) 
        if (label1.Text.equals(comboBox1.Text)) 
        {
            label1.Text = "";
        }
    }
    
answered by 24.05.2017 / 15:13
source
1

As I understood, you want that at the moment of selecting one of the options of the combobox, in the label the message with the selected locality is shown, right?

I could use the SelectedIndexChanged event, then take the text from the combobox and concatenate it with the message, then send it to the label.

    
answered by 24.05.2017 в 02:57