Solved

VB.Net Winform - TextBox Validation

Posted on 2010-08-31
6
801 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

16 Experts available now in Live!

Get 1:1 Help Now