473,699 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2417
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******** ******@TK2MSFTN GP11.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(ByVa l sender As Object, _
ByVal e As System.EventArg s) 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_LostFoc us
Next
End Sub
Private Sub TextBox_LostFoc us(ByVal sender As Object, _
ByVal e As System.EventArg s)
DirectCast(send er, 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
4360
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 color formatting. The code I used is below but it does not work. Can someone please help me out, its rather urgent and important. <% function nl2br(str)
0
1510
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 the textbox object using either the Controls orFindControl method but it's always returning an empty *.Textinstead of the value displayed on the screen. Below are snippetsof my code - anybody there who can help me PLEASE? =====*.vb <edit mode...
2
1306
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 this:
2
2569
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 this:
7
2131
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 following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
7
1695
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 Default.aspx. From Default.aspx, on page load, I populate the textbox through the public property TextBoxBody of MyControl.ascx. When I load Default.aspx and change what's in the text box and click the button to update the database, the update statement...
8
5757
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 can do only with ajax(xml and javascript) but i want to fetch possible values from database and want to show as the user types in text box.
4
6946
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) can anyone provide a snippet of code please many thanks
3
10800
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 months date in another textbox. and while pressing the second button (submit) i need to display the date displayed in the textbox as itself and the records between thoses two dates. if that date is still there in the textbox only i can sort the...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.