A Validating Edit Control

The Problem

The DDV mechanism is far too primitive to be useful. It only validates on the OK button (or, more specifically, on the UpdateData that accompanies it), which delays the validation until far too late. It also issues error messages that are related to the representation in the program, not to the problem domain. I have thus avoided this toy mechanism and written my own validation code. I also find it particularly annoying that I am allowed to click the OK button when there is an error; this violates the basic principles of GUI design. So DDV is not only hard for the user to use, it actually violates the GUI design guidelines since normally you must click a button which is not actually valid to click before the DDV mechanism can be invoked!

Sure, it makes it easier to program. But the goal is not to make applications easy to program as much as it is to make applications easy to use. I believe my techniques contribute significantly to the latter. The fact that they are not easier to program is of little consequence.

This particular example is useful as it illustrates several useful techniques. These include

  • Showing how to validate input on a character-by-character basis
  • Providing useful feedback immediately as to the correctness of the input
  • Showing how to use a ToolTip to indicate the reason that the OK button is disabled.

I have used all of these techniques in some form or other in building very informative, user-oriented validation methods.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan