Solved

VB.Net Winform - TextBox Validation

Posted on 2010-08-31
6
806 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 27

Expert Comment

by:Ark
ID: 33574987
For numeric only you can set ES_NUMBER style
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now