Search code examples
vb.netcomboboxreturn-valuemessagebox

MessageBox with a comboBox inside and return the value of the comboBox


I would like to show a messageBox with a comboBox display on the messageBox and returning the comboBox result. But I dun noe how to add a comboBox inisde the messageBox. I'm using visual studio and the programming language is vb.net. Anyone can help?
The messageBox I want is MessageBox.Show(), Not MsgBox().
Thx for your help~~


Solution

  • Use a custom Form instead with .ShowDialog() method. You may have to somehow override the DialogResult Enumeration though I'd think just passing back whatever you need may be simpler.

    Update: If the combobox provides integer values, you could do something like this if you set DialogResult to that integer in your custom form. FYI ShowMsg is my overloaded function that will display my custom form based on the arguments sent.

    Dim Result As DialogResult = _
        ShowMsg("Select from the combobox", "Select an integer", ShowMsgButtons.OK, ShowMsgImage.Exclmation, ShowMsgDefaultButton.Button1)
    Select Case Result
        Case 10
            'what happens when they select 10 from the combobox
        Case 20
            'what happens when they select 20 from the combobox
        Case 30
            'what happens when they select 30 from the combobox
    End Select