473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

TextBox Trim question

It is hard for me to imagine a time when you would not want to have the data
in a textbox control trimmed. I am hoping there is some sort of switch that
can be set for all text boxes so that when the user leaves the text box it
gets trimmed. Is there such a thing. If not, does this mean I need to
write some sort of trimming code for each text box I place on a Winform. If
so, what is the simplest and easiest way for me to see to it that all text
boxes get trimmed?

Nov 20 '05 #1
7 2402
AFAIK, there's not a built in method for this but you could easily derive a
control and when text is 'set', make sure you trim it in there.
"Woody Splawn" <wo***@splawns.com> wrote in message
news:OY**************@TK2MSFTNGP11.phx.gbl...
It is hard for me to imagine a time when you would not want to have the data in a textbox control trimmed. I am hoping there is some sort of switch that can be set for all text boxes so that when the user leaves the text box it
gets trimmed. Is there such a thing. If not, does this mean I need to
write some sort of trimming code for each text box I place on a Winform. If so, what is the simplest and easiest way for me to see to it that all text
boxes get trimmed?

Nov 20 '05 #2
Cor
Hi Woody,

Two days ago someone did ask something, that did look strange in all the
answer that have been given here, but when we did something (not one person
but more persons) in this newsgroup it did work and it is quiet normal that
it does work.

I thought with that I can do in future something.
Now you are asking for something I thought that I could, so I did make it.

Try it, I thought that it does what you ask

I hope this was what you where looking for?

Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim txtboxarea As TextBox() = New TextBox() {TextBox1, TextBox2}
'In the array are all the textboxes you want to trim that you made in design
time
For Each txt As TextBox In txtboxarea
AddHandler txt.LostFocus, AddressOf TextBox_LostFocus
Next
End Sub
Private Sub TextBox_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, TextBox).Text = _
Trim(DirectCast(sender, TextBox).Text)
End Sub
///



It is hard for me to imagine a time when you would not want to have the data in a textbox control trimmed. I am hoping there is some sort of switch that can be set for all text boxes so that when the user leaves the text box it
gets trimmed. Is there such a thing. If not, does this mean I need to
write some sort of trimming code for each text box I place on a Winform. If so, what is the simplest and easiest way for me to see to it that all text
boxes get trimmed?

Nov 20 '05 #3
"Woody Splawn" <wo***@splawns.com> schrieb
It is hard for me to imagine a time when you would not want to have
the data in a textbox control trimmed. I am hoping there is some
sort of switch that can be set for all text boxes so that when the
user leaves the text box it gets trimmed. Is there such a thing. If
not, does this mean I need to write some sort of trimming code for
each text box I place on a Winform. If so, what is the simplest and
easiest way for me to see to it that all text boxes get trimmed?


solution 1: write a derived Textbox that trims in the leave event.
solution 2: handle the leave event in the same event handler for all
textboxes.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
* "Woody Splawn" <wo***@splawns.com> scripsit:
It is hard for me to imagine a time when you would not want to have the data
in a textbox control trimmed. I am hoping there is some sort of switch that
can be set for all text boxes so that when the user leaves the text box it
gets trimmed. Is there such a thing. If not, does this mean I need to
write some sort of trimming code for each text box I place on a Winform. If
so, what is the simplest and easiest way for me to see to it that all text
boxes get trimmed?


You can create an inherited control (inheriting from
'System.Windows.Forms.TextBox' which handles its 'Validating' event and
trims its contents there. Then you will have to use the new textbox
instead of the standard Windows Forms textbox.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Cor
Hi Herfried,

Did you look at my solution I think it is wonderful?

Cor
You can create an inherited control (inheriting from
'System.Windows.Forms.TextBox' which handles its 'Validating' event and
trims its contents there. Then you will have to use the new textbox
instead of the standard Windows Forms textbox.

Nov 20 '05 #6
HI Woody,

Did you have any concern on this issue?
If so please post in the newsgroup.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #7
HI Woody,

Did you have any concern on this issue?
If so please post in the newsgroup.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jonathan | last post by:
Hi, I have to use the nl2br function in the asp file, luckly I got this code from a site. What I need done is to display textbox content the way it was typed/pasted i.e. with paragraph breaks and...
0
by: Tetet B via .NET 247 | last post by:
I'm using VB.Net and trying to retrieve the data in the textboxcell of a datagrid after a successful display (used Databind).User can either display data or enter data in the textbox. I canalways get...
2
by: Alex Shirley | last post by:
HI I'm trying to iterate through all the textboxes on a webpage and trim them for spaces. i.e. If a user enters " hello world " we correct it to "hello world" So far I've come up with...
2
by: Alex Shirley | last post by:
HI I'm trying to iterate through all the textboxes on a webpage and trim them for spaces. i.e. If a user enters " hello world " we correct it to "hello world" So far I've come up with...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
7
by: Jason | last post by:
I have created a user control, MyControl.ascx, that has a text box and a button. The button updates a table in SQL with the text in the textbox. Now, I include that control in a page...
8
by: nil | last post by:
Hello all, It's urgent... i want to add autocomplete textbox facility in my application like google. as you type it suggests option to the user..i want the same kind of facility...i know i...
4
by: viv | last post by:
how do you trap keyboard codes for text box in VB2005 ? I'm looking for a code snippet to only allow numeric input in a text box (same as Key event in VB6, then use Keyascii to decide action) ...
3
by: remya1000 | last post by:
i'm using ASP with MSAccess as database. i have two buttons and two textbox in my page. when i press my first button (First month) i need to display the current month in one textbox and last one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.