How to display a Messagebox when selecting an item in the combobox

2

I would like to know how to implement in my combobox a Messagebox when selecting an item from the list?

Example:

Combo List:

  • Junior
  • Maria
  • Joseph
  • When you select Mary, a message box will appear stating: You have selected "Mary", OK button.

        
    asked by anonymous 01.12.2017 / 14:12

    1 answer

    5

    The ComboBox has a SelectedIndexChanged event, you simply implement it and add MessageBox to show the desired message.

    Something like

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MessageBox.Show($"Você selecionou o item {(sender as ComboBox).Text}");
    }
    

    To add the event to your component. In the design mode of your form, select the component, right-click on it, and then on Properties . In the Properties window, click the Events icon (lightning) in the Behavior category, double click on the event you want to create for component, in this case the event SelectedIndexChanged

        
    01.12.2017 / 14:18