Validating input on child dialog... - Programmer
This is a discussion on Validating input on child dialog... - Programmer ; All, I have a fairly substantial C++ MFC dialog app, complete with a
property sheet and a number of property pages. Anyway one of these pages
when a button is clicked displays a small "enter value" child dialog. My
problem ...
-
Validating input on child dialog...
All, I have a fairly substantial C++ MFC dialog app, complete with a
property sheet and a number of property pages. Anyway one of these pages
when a button is clicked displays a small "enter value" child dialog. My
problem is that I want to validate input in this edit box so that the values
are only e.g "20", "40", "40" etc etc.
I'm unsure of how to do this without constantly closing the dialog and then
making it re-appear. I should do this validation in the child form
presumably but i don't really know what is the best approach to solve this
problem. I know i could use a combo box, but for reasons I won't go into I
don't really want to.
Sugguestions?
PT
-
Re: Validating input on child dialog...
On Sat, 24 Jan 2004 10:52:41 -0000, "Paul Tomlinson"
wrote:
>All, I have a fairly substantial C++ MFC dialog app, complete with a
>property sheet and a number of property pages. Anyway one of these pages
>when a button is clicked displays a small "enter value" child dialog. My
>problem is that I want to validate input in this edit box so that the values
>are only e.g "20", "40", "40" etc etc.
>
>I'm unsure of how to do this without constantly closing the dialog and then
>making it re-appear. I should do this validation in the child form
>presumably but i don't really know what is the best approach to solve this
>problem. I know i could use a combo box, but for reasons I won't go into I
>don't really want to.
>
>Sugguestions?
>
>PT
>
I'm not sure exactly what your question is. You can
get the entered value and massage it to the nearest
value you find acceptable, then write that back to
the control. You should have a separate OK button
for the user to click when completed, since if you
remove the dialog right after entry, the updated value
won't get seen.
As an aside here, my own preference is to be able
to hit Enter after typing in the number, to conclude
the entry of that variable, but *not* close the dialog.
To make that work I have an "Apply" button next to
the OK button, and I make that the default so it gets
the Enter key instead of the OK. You can do the
same thing with an invisible button instead of Apply.
The user then clicks on OK, or hits ESC to exit.
Just my $0.02 worth.
Bob Masta
dqatechATdaqartaDOTcom
D A Q A R T A
Data AcQuisition And Real-Time Analysis
www.daqarta.com
-
Re: Validating input on child dialog...
"Paul Tomlinson" wrote in message
news:butist$l2854$1@ID-116287.news.uni-berlin.de...
> All, I have a fairly substantial C++ MFC dialog app, complete with a
> property sheet and a number of property pages. Anyway one of these
pages
> when a button is clicked displays a small "enter value" child dialog. My
> problem is that I want to validate input in this edit box so that the
values
> are only e.g "20", "40", "40" etc etc.
>
> I'm unsure of how to do this without constantly closing the dialog and
then
> making it re-appear. I should do this validation in the child form
> presumably but i don't really know what is the best approach to solve
this
> problem. I know i could use a combo box, but for reasons I won't go
into I
> don't really want to.
"Dialog Data Exchange and Validation"
<http://msdn.microsoft.com/library/en...ialog_Data_Exc
hange_and_Validation.asp>
-
Re: Validating input on child dialog...
"Paul Tomlinson" wrote in message news:...
> All, I have a fairly substantial C++ MFC dialog app, complete with a
> property sheet and a number of property pages. Anyway one of these pages
> when a button is clicked displays a small "enter value" child dialog. My
> problem is that I want to validate input in this edit box so that the values
> are only e.g "20", "40", "40" etc etc.
>
> I'm unsure of how to do this without constantly closing the dialog and then
> making it re-appear. I should do this validation in the child form
> presumably but i don't really know what is the best approach to solve this
> problem. I know i could use a combo box, but for reasons I won't go into I
> don't really want to.
>
Sounds to me like you want to do validation in-place. My preferred
method for this is to subclass the edit control and then override the
OnKillFocus(). In this I do the validation, retaining focus if
invalid. Of course you have to then trap whether you're losing focus
because of the dialog being cancelled, etc., but if you've a lot of
input controls then it's worth the effort.
If you've only a simple problem (i.e. one edit box) then this is
probably overkill. In which case, take a look at Q142481 "FCSVAL32
Control-by-Control Validation in MFC" on the MS KB.
HTH
Paul.