Results 1 to 12 of 12

Thread: [RESOLVED] combobox Dropdown UPPERCASE??!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Calgary, AB Canada
    Posts
    42

    Resolved [RESOLVED] combobox Dropdown UPPERCASE??!!!

    Unlike the textbox, a combobox does not have the CharacterCasing property. That would be too easy.

    Here is my problem. I have a dropdown combobox that contains a number of values obtained from a database. However the user can, "should" he choose to do so, manually enter a new value. I want to make sure that any alpha characters he/she enters be uppercase.

    There "appears" to be no eloquent way to do this. I have done much searching and the few answers here either simply do not work, or deal with processing the list of options and not with actual keyboard input.

    I have been reduced to reformatting in uppercase on the combobox exit event. (Ths is not what I would refer to as an elegant solution)

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: combobox Dropdown UPPERCASE??!!!

    VB Code:
    1. If Convert.ToInt32(e.KeyChar) >= 97 AndAlso Convert.ToInt32(e.KeyChar) >= 122 Then
    2.                 e.KeyChar = Convert.ToChar(e.KeyChar.ToString.ToUpper)
    3.             End If
    Last edited by wild_bill; Apr 18th, 2006 at 12:41 AM.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,439

    Re: combobox Dropdown UPPERCASE??!!!

    VB Code:
    1. Private Sub ComboBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
    2.         If Char.IsLetter(e.KeyChar) Then
    3.             e.KeyChar = Char.ToUpper(e.KeyChar)
    4.         End If
    5.     End Sub

  4. #4
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: combobox Dropdown UPPERCASE??!!!

    i think he was referring to the first letter only

    mike to be Mike and not MIKE, i think

    so the solution might be only be replacing the first character with it's upper case character.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,439

    Re: combobox Dropdown UPPERCASE??!!!

    Quote Originally Posted by maged
    i think he was referring to the first letter only

    mike to be Mike and not MIKE, i think

    so the solution might be only be replacing the first character with it's upper case character.
    I'm guessing not from the THREAD TITLE and also the fact that the TextBox.CharacterCasing property is incapable of doing that.

  6. #6
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: combobox Dropdown UPPERCASE??!!!

    I want to make sure that any alpha characters he/she enters be uppercase.
    what does he mean by alpha ??

  7. #7
    Lively Member
    Join Date
    Mar 2006
    Posts
    88

    Re: combobox Dropdown UPPERCASE??!!!

    Quote Originally Posted by maged
    what does he mean by alpha ??
    As in Alphanumeric? As opposed to Numeric?
    Using Visual Studio 2005 / Framework 2.0

  8. #8
    Junior Member
    Join Date
    Dec 2004
    Posts
    17

    Re: combobox Dropdown UPPERCASE??!!!

    Quote Originally Posted by jmcilhinney
    VB Code:
    1. Private Sub ComboBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
    2.         If Char.IsLetter(e.KeyChar) Then
    3.             e.KeyChar = Char.ToUpper(e.KeyChar)
    4.         End If
    5.     End Sub

    Sorry, the e.KeyChar is read only, how can I assign data to it?

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,439

    Re: combobox Dropdown UPPERCASE??!!!

    Quote Originally Posted by lamnic
    Sorry, the e.KeyChar is read only, how can I assign data to it?
    Well, there's direct proof that everyone should be specifying which version they are using. In 2003 the e.KeyChar property is ReadOnly in the KeyPress event handler while in 2005 it isn't. In 2003 you could use this:
    VB Code:
    1. Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
    2.         If Char.IsLetter(e.KeyChar) AndAlso e.KeyChar <> Char.ToUpper(e.KeyChar) Then
    3.             'Reject the lower case character.
    4.             e.Handled = True
    5.  
    6.             'Replace with the corresponding upper case character.
    7.             Me.ComboBox1.SelectedText = Char.ToUpper(e.KeyChar)
    8.         End If
    9.     End Sub

  10. #10
    Junior Member
    Join Date
    Dec 2004
    Posts
    17

    Re: combobox Dropdown UPPERCASE??!!!

    Thx.

  11. #11

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Calgary, AB Canada
    Posts
    42

    Re: combobox Dropdown UPPERCASE??!!! (Resolved)

    Thanks for the input everyone. The code provided by "jmcilhinney" did the trick.

  12. #12
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: [RESOLVED] combobox Dropdown UPPERCASE??!!!

    Well, there's direct proof that everyone should be specifying which version they are using. In 2003 the e.KeyChar property is ReadOnly in the KeyPress event handler while in 2005 it isn't
    that is a great piece of information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width