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

Asked

Viewed 328 times

2

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

Example:

Combo list:

  1. Junior
  2. Maria
  3. Joseph

When selecting Maria, a message box appears stating: You selected "Maria", OK button.

  • Jose edit your question and include the code with what you already tried.

1 answer

5

The ComboBox has an event SelectedIndexChanged, just implement it and add a 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 mode design from your form, select the component, right-click on it and then Properties. In the window of Properties click on the icon of Events (lightning) in the category Behavior, two-click on the event you want to create for the component, in this case the event SelectedIndexChanged

Browser other questions tagged

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