943,728 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2860
  • C# RSS
May 3rd, 2009
0

Can't clear textbox

Expand Post »
Hi Folks,

I have a textbox which looks out for keypresses when it is in focus.
For example, when the ";" key is pressed, a few functions are called. THe problem is, is that in the KeyPress function for the textbox, i have textbox1.Text = ""; to clear it however it doesn't work.

It's as if the text box executes the KeyPress function (hence my clear statement) prior to actually outputting the ";" in the box.

So in the end, ";" gets displayed (However if I keep pressing ";", I only ever see one)

Any ideas on how I can fix this? Thanks
Last edited by jonnytabpni; May 3rd, 2009 at 7:07 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
jonnytabpni is offline Offline
39 posts
since May 2009
May 3rd, 2009
0

Re: Can't clear textbox

Simple... Just set e.Handled to true
When e.Handled is set to true, then the keypress event stops there, otherwise it is passed up the chain to the TextBox.
// Jerry
Last edited by JerryShaw; May 3rd, 2009 at 7:20 pm.
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
May 4th, 2009
0

Re: Can't clear textbox

Thanks! worked brill!
Reputation Points: 10
Solved Threads: 0
Light Poster
jonnytabpni is offline Offline
39 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Binding SelectedValue from Dataset
Next Thread in C# Forum Timeline: Detecting access data change in C#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC