PC Review


Reply
Thread Tools Rate Thread

Character Casing in Combo

 
 
UmmagummA
Guest
Posts: n/a
 
      30th Dec 2004
How to make a ComboBox to display characters only in Upper or Lower Case as
you type?

I was trying to override OnKeyDown and OnKeyPress but coudn't figure it
out. The problem is that in OnKeyPress
new key value is not writed in the Combo.Text until the event is executed.


 
Reply With Quote
 
 
 
 
Morten Wennevik
Guest
Posts: n/a
 
      30th Dec 2004
Hi UmmagummA,

What you do in the KeyPressEvent is set e.Handled = true to prevent the
characters ever reaching the ComboBox. Instead add a character of your
own.

Something like this might work for you, given a ComboBox b and its
KeyPressEvent b_Press

private void b_Press(object sender, KeyPressEventArgs e)
{
if(Char.IsLetter(e.KeyChar))
{
e.Handled = true;
string s = e.KeyChar.ToString();
b.Text += s.ToUpper();
b.SelectionStart = b.Text.Length;
}
}


--
Happy Coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      30th Dec 2004
Even better, using Char.ToUpper

if(Char.IsLetter(e.KeyChar))
{
e.Handled = true;
b.Text += Char.ToUpper(e.KeyChar);
b.SelectionStart = b.Text.Length;
}


--
Happy Coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
UmmagummA
Guest
Posts: n/a
 
      30th Dec 2004
Huge Thanks!

When I saw it, I tought, why I didn't think of it )


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Box typing a Character does nothing =?Utf-8?B?TG93ZTUwMDA=?= Microsoft Access Forms 2 14th Feb 2007 08:45 AM
Re: Character limit for combo boxes Rick Brandt Microsoft Access Form Coding 4 28th Dec 2006 12:23 AM
Replace a character in combo box Kay Microsoft VB .NET 5 23rd Aug 2006 06:17 AM
Q: Character Casing in a ComboBox Visual Systems AB \(Martin Arvidsson\) Microsoft C# .NET 3 1st Nov 2005 09:01 PM
Combo Box- Character Look Up 201blue3 Microsoft Excel Misc 1 7th Jul 2004 05:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.