Force Upper in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard MSL

    Force Upper in C#

    How do you make a ComboBox force casing to uppercase? With a TextBox, I do
    this:
    TextBox txtName;
    this.txtName.Ch aracterCasing = CharacterCasing .Upper;

    And it makes whatever the user types appear in upper case, which is what I
    want. But with a ComboBox, if I do this:

    ComboBox TCombo;
    this.TCombo.Cha racterCasing = CharacterCasing .Upper;

    It fails, because CharacterCasing is not a member of the ComboBox class. How
    should this be done? Thanks.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Force Upper in C#

    Richard,

    In order to do this, you will have to subclass the ComboBox, or handle
    the appropriate events to cause the change in behavior that you want. I
    think the easier way is to create a custom ComboBox where you override the
    OnKeyDown and OnKeyUp (and maybe the OnKeyPress) methods and alter the
    KeyEventArgs instance passed in to represent an upper-case character being
    typed. I'm not positive it will work. If it doesn't, then you will
    probably have to override the WndProc method and handle the appropriate
    windows messages that handle key events, and modify them so that they
    represent an upper case character.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Richard MSL" <RichardKirknes s@nospam.nospam > wrote in message
    news:9B27366C-24B2-4615-BD5B-9345D2D92987@mi crosoft.com...[color=blue]
    > How do you make a ComboBox force casing to uppercase? With a TextBox, I do
    > this:
    > TextBox txtName;
    > this.txtName.Ch aracterCasing = CharacterCasing .Upper;
    >
    > And it makes whatever the user types appear in upper case, which is what I
    > want. But with a ComboBox, if I do this:
    >
    > ComboBox TCombo;
    > this.TCombo.Cha racterCasing = CharacterCasing .Upper;
    >
    > It fails, because CharacterCasing is not a member of the ComboBox class.
    > How
    > should this be done? Thanks.
    >[/color]


    Comment

    • cody

      #3
      Re: Force Upper in C#

      if you add items to the combobox do:

      myCombo.Items.A dd(myString.ToU pper());



      "Richard MSL" <RichardKirknes s@nospam.nospam > schrieb im Newsbeitrag
      news:9B27366C-24B2-4615-BD5B-9345D2D92987@mi crosoft.com...[color=blue]
      > How do you make a ComboBox force casing to uppercase? With a TextBox, I do
      > this:
      > TextBox txtName;
      > this.txtName.Ch aracterCasing = CharacterCasing .Upper;
      >
      > And it makes whatever the user types appear in upper case, which is what I
      > want. But with a ComboBox, if I do this:
      >
      > ComboBox TCombo;
      > this.TCombo.Cha racterCasing = CharacterCasing .Upper;
      >
      > It fails, because CharacterCasing is not a member of the ComboBox class.[/color]
      How[color=blue]
      > should this be done? Thanks.
      >[/color]


      Comment

      Working...