[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Force the validation of a TextBox

Posted on 2004-04-16
5
Medium Priority
?
808 Views
Last Modified: 2008-01-09
Hello,

I have a form with several custom textboxes. For each textbox, I have overriden the OnValidating method (or handling the Validating event) to validate the input and display an error using an errorProvider.
So the validation is done when the user is filling the form.

But when I want to save the form, I want to revalidate everything (to get some Ids from database, ...). To do that I want to force the validation of each control and I was looping on all controls and calling the Focus method.
This is quite dirty I think and visually, the effect is not really nice.

So I was thinking about implementing a Validate public method on my Textbox. This method will call internally the protected OnValidating method. The result will be the same but without any ugly visual effect.

What is your opinion about that solution ? Don't you think that using a public method to call a protected method is breaking the encapsulation of the Textbox ?
Do you have any other / better solution ?
Thanks !

Jarod
0
Comment
Question by:Jarodtweiss
[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
  • 2
  • 2
5 Comments
 
LVL 9

Assisted Solution

by:malharone
malharone earned 240 total points
ID: 10845273
this is a great article .. hope it gives you better direction for this problem

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms03162004.asp
0
 
LVL 4

Author Comment

by:Jarodtweiss
ID: 10845819
yes I know that article.
It is a different kind of validation and I didn't want to migrate to that kind of validation.
I wanted a kind of textboc autovalidating itself...
0
 
LVL 5

Expert Comment

by:Xentor_
ID: 10845891
Hmm... Other possible solutions...

1) Make a globally-scoped object that'll raise an event on command.  Have all of the textboxes automatically add a handler to this event on creation, and have them revalidate when it's triggered.

2) Create a shared Validate method in your text box class.  When a textbox is created, it could add a weak reference to itself into a private shared collection.  The Validate method could iterate through the collection and trigger the Validate for each object.

3) Have the textboxes automatically bind one of their properties to the form's tag, for example.  When that property changes, trigger an update.

Just some random thoughts... Not very good, but maybe they'll inspire you.
0
 
LVL 4

Author Comment

by:Jarodtweiss
ID: 10848335
Before accepting one answer, I'm waiting for one answer. What do you think of implementing a Validate method that will encapsulate a call to the OnValidate method ?
0
 
LVL 5

Accepted Solution

by:
Xentor_ earned 510 total points
ID: 10850195
Well, I don't know if that breaks the almighty rules of OOP, but I would probably put the code in a public function and have the OnValidate override call that function instead.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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