Solved

VB.Net Winform - TextBox Validation

Posted on 2010-08-31
6
809 Views
Last Modified: 2012-05-10


VS 2005 / Vb.Net - Windows Application

I have almost 30 TextBox - For which i need  to handle Events like only Characters or Numbers ?

1) How to perform this

2) Is there any way  to write a Common Class and pass it on Event Handler of TextBox

Or Do i need to write some code on each and every textbox
0
Comment
Question by:chokka
6 Comments
 
LVL 8

Accepted Solution

by:
Mikkk earned 167 total points
ID: 33574245

1 - Name every textbox different as if they has to be numeric values or text values, for example NTextBox1 will be numeric and TTextBox1 eill be text
2 - Assign the save procedure to each event of each control, and make this procedure process one or other thing by his name like the code attached.




    Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NTextBox1.TextChanged, NTextBox2.TextChanged, TTextBox1.TextChanged
        If sender.name.startswith("N") Then
            'is a numeric field
        Else
            'is a char field
        End If
    End Sub

Open in new window

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33574609
You're better option would be to create a custom control, derived from textbox, that implements this custom behaviour. But I guess it depends on how much time you have to devote to something like that.
0
 
LVL 28

Expert Comment

by:Ark
ID: 33574987
For numeric only you can set ES_NUMBER style
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 33575180
0
 
LVL 8

Expert Comment

by:Mikkk
ID: 33576170
What I've written maybe is not the best way, but is the fastest way is you has the form drawn and the controls positioned.
If you only want to validate numbers, chars when an event occurs (in the example TextChanged but can be Validated) this is a fast solution.
0
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 166 total points
ID: 33590612
Select all the textboxes You want for raising the same event handler and find the event in properties window, doubleclick it or write a event handler name. This will add one event handler for all selected controls.
Hope it helps
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question