❔ MessageBox.Show on ComboBox selected item (C# Windows Form)
Can someone help me on how to use MessageBox whenever I click an item from the ComboBox?
Example: I will click Earth then I want it to display message about the ID of Earth and Description (From saved Database)
17 Replies
how are you handling the selection?
If this is a WinForms application, then check out the events that the combobox has. It should provide you with a SelectionChanged event. That is what you want. Via said.event you'd catch whenever the user selects something and display your message box accordingly
I think it's missing something, coz it doesn't show the message
Is the selected item truly a datarowview?
Try writing the following before the if condition:
You could also figure this out by setting a breakpoint and debugging
I'd place a breakpoint on line 61, you can do this by clicking the line number on the left, or by pressing F9 on your keyboard
and why does your event handler have 2 references + _1 suffix
@BakaAqua >< could you please share a screenshot of the WinForms designer window, with the combobox selected and it's event settings displayed? It is possible that you have an incorrect event bound to the control
I forgot to remove that one, .... it's remove now
this is crucial
The name of the event is either wrong or cut off by the window. Is the bound event called CbxDatashow_Selected or is it something longer?
SelectedIndexChanged
Then this event won't run, as it is SelectedIndexChanged_1
Any advice of what would be the appropriate event to use?
How many selectionChanged event handlers do you have in your code
It seems that you have multiple
I cannot suggest, because you create the event handlers
Only one in this form
Oh okay thanks
Did you make sure the correct event handler is being fired?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.