Event procedure from Combo Box Drop-Down

DonClaf

New member
Joined
Jul 24, 2011
Messages
4
Programming Experience
Beginner
Hi Everybody. Appreciate any help I can get - haven't done anything like this in a long time, so I apologize if this is an overly basic question.

I've created a form to handle "frequently asked questions". In the form I have five Drop-Down Combo Boxes and I want the user to be able to select one of the questions listed in the drop down boxes and have it return a "message box" with the answer to the question.

Naturally I'll have different "answers" for each question, but my initial efforts have me getting my message box as soon as I click on the drop-down arrow itself, and I don't want that triggered until I click on the specific question.

Any guidance will be much appreciated.

Thanks.
 
You're obviously handling the wrong event, probably Click. The event of most interest for a ComboBox is SelectedIndexChanged, which is raised whenever the value of the SelectedIndex property changes. That includes changes made by the user and in your code. If the latter is an issue then you can handle SelectionChangeCommitted instead, which responds to changes made by the user only.
 
I understand what you're saying

Thanks. Actually I had moved my msgbox in the "ComboBox1_SelectedIndexChanged" so it only gives me the message when I select the actual item. The thing is, I have five items in each "collection" of my five drop-down and I want to display a different msg box each time I select a different item. Again, I haven't done this for quite a while, and I would suspect that I should use a "Select Case Statement" and treat each item as a different index number. Hate to sound like a complete dunder-head, but I guess it is what it is. I'll play with it a little more and maybe I'll be able to come up with a question that makes a little more sense.
Don
icon11.png
 
This little sample works. See if you can adapt it to your code:

VB.NET:
 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim mycolor As String = ""
        Select Case ComboBox1.SelectedIndex
            Case 0
                mycolor = "An apple is red."
            Case 1
                mycolor = "A banana is yellow."
            Case 2
                mycolor = "The sky is blue."
            Case 3
                mycolor = "The grass is green."
            Case 4
                mycolor = "An orange is orange."
            Case 5
                mycolor = "A grape is purple."
            Case 6
                mycolor = "Slate is black."
            Case 7
                mycolor = "Snow is white."
        End Select
        MessageBox.Show(mycolor)
    End Sub
 
Yes, it looks like it's going to do it. Two other little things and I'm sure I'll be able to find out as I go along. But, when I changed the style of my combo box to drop-down List, I lost the "heading" - as I recall in VB6, all you had to do was put in a Combobox1 = "Whatever title you want", and I would suspect that it's similar in dot net and I'll find out quickly. One other question though, what are the maximum number of characters allowed in a "message box"? Thanks again for your help, and I do hate sounding like such a "doofus".
Don
 
Back
Top