Skip to content

Instantly share code, notes, and snippets.

@rhildred
Last active October 7, 2015 18:02
Show Gist options
  • Save rhildred/e45fd5e5a2c2de29cc5f to your computer and use it in GitHub Desktop.
Save rhildred/e45fd5e5a2c2de29cc5f to your computer and use it in GitHub Desktop.
Something that I came across in VB forms with Combo Box

When creating a combo box, there are 2 messages that trigger in a windows forms app.


    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        MessageBox.Show(ComboBox1.SelectedItem.ToString() & " was selected")
    End Sub

and when text is entered in to the top portion of the combo box:

    Private Sub ComboBox1__OnKeyPress(sender As Object, e As KeyPressEventArgs) Handles ComboBox1.KeyPress
        If (e.KeyChar = ChrW(13)) Then
            MessageBox.Show(ComboBox1.Text & " was typed")
        End If
    End Sub

The part that seemed a bit obscure to me was that to read the character that was pressed (and make sure that it is an enter key in this case) one needs to do a ChrW cast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment