Force Upper in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do you make a ComboBox force casing to uppercase? With a TextBox, I do
this:
TextBox txtName;
this.txtName.CharacterCasing = 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.CharacterCasing = CharacterCasing.Upper;

It fails, because CharacterCasing is not a member of the ComboBox class. How
should this be done? Thanks.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top