[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB.Net Winform - TextBox Validation

Posted on 2010-08-31
6
Medium Priority
?
816 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Accepted Solution

by:
Mikkk earned 668 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 668 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 664 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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