Uppercase in Combobox text

  • Thread starter Thread starter Lakshmi
  • Start date Start date
L

Lakshmi

Hi,

How can I make the combo box text uppercase? For instance when the user
types in letters in the combobox, I want them to appear as upper case.

Thanks.

Lakshmi
 
Lakshmi said:
Hi,

How can I make the combo box text uppercase? For instance when the user
types in letters in the combobox, I want them to appear as upper case.

Thanks.

Lakshmi
You could trap them manually in the textchanged event (bearing in mind
that the text might have changed because an item was selected).

JB
 
Use the following code in the keypress event of the combo box to convert the
letters to upper case:

string str = e.KeyChar.ToString().ToUpper();
char[] ch = str.ToCharArray();
e.KeyChar = ch[0];
 
Laskhmi,

This you can do in the same way as the thousands of numeric textboxes and
autocompleteboxes samples are done on internet.

Be aware not to use the keypress but the keyup event. The later gives
information about the key that has been pressed.

For the rest it is just MyPressedcharstring.ToUpper

I hope this helps,

Cor
 
Do you want the items in the list to also be uppercase? If so, a simple
override will do the trick:

class UppercaseComboBox : ComboBox
{
private const int CBS_UPPERCASE = 0x2000;
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.Style |= CBS_UPPERCASE;
return p;
}
}
}

/claes
 

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

Similar Threads


Back
Top