I have a number of controls on a tab page. I want to validate them
all
when the user tries to leave the tab. I then want to highlight the
first control which fails validation. How can I do this? I try
setting
focus but something seems to set the focus back to the control which
had it before validation. Any ideas?
TIA,
KK
Hi Kev,
Are you using or tried the ErrorProvider control? (find it in the
"Components" toolbox, or "All Windows Forms" toolbox) This offers - by
default - a red circle "blob" + exclamation mark that will blink for a few
seconds and provide a tooltip of the error against any control you want to
have it. E.g. textboxes, list controls, etc. Remains invisible when not
set.
e.g. to set:
me.err.seterror(me.mytextbox, "My error text")
To clear a single instance:
me.err.seterror(me.mytextbox, "")
Validation can be done either on each control's change event (which I
commonly use, but it does depend on what you're trying to achieve), or after
a single large event, such as your change of tab page. I would suspect you
would need to ensure that you re-select the tab page (if you have a set of
more than one tab anyway), so that the relevant tab is topmost and thus
visible to the user, then you would set the focus to whichever control on
the tab you want.
Hope that helps.
Al
>I have a number of controls on a tab page. I want to validate them
> all
[quoted text clipped - 6 lines]
> TIA,
> KK
kelvin.koogan@googlemail.com - 15 Jan 2008 15:53 GMT
> Hi Kev,
>
> Are you using or tried the ErrorProvider control?
Good suggestion, thanks.
However I'm having a problem with the ErrorProvider (in C++, VS2005).
If the ErrorProvider is highlighting an error then it is impossible to
change a checkbox or dropdown a dropdownlist. This includes if these
controls are the ones with the errors. So for example if the user
needs to select something different from a dropdownlist they can not
because the dropdownlist is opened and then immediately closes again.
Any ideas what is wrong?
TIA,
KK
Alec MacLean - 15 Jan 2008 16:10 GMT
Hi Kelvin,
I haven't experienced that issue before - though I'm using VB.NET rather
than C++. I wouldn't have thought it would make such a behaviour difference
occur though. I don't have C++ installed either, so can't experiment.
However, there is an MSDN example of using the ErrorProvider that includes a
C++ version. It's for VS 2003, but usage shouldn't be much, if any,
different:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.errorprovider(VS.7
1).aspx
Maybe that can help you with the next step?
Also a search on "c++ errorprovider" turns up quite a bit in Google.
Al
>> Hi Kev,
>>
[quoted text clipped - 13 lines]
> TIA,
> KK
kelvin.koogan@googlemail.com - 15 Jan 2008 21:20 GMT
> >> Are you using or tried the ErrorProvider control?
>
[quoted text clipped - 13 lines]
>
> - Show quoted text -
It seems I've stumbled across a combination of factors which cause
this problem.
I have a tab control. I'm performing validation on the TabPages where
I valid all the controls on the page. I put up a MessageBox to tell
the user to fix the errors.
This combination shows the problem. If I don't put up the MessageBo
then it works OK.
Any idea why this might be?
TIA,
KK
Alec MacLean - 16 Jan 2008 09:19 GMT
Possibly due to the messagebox taking focus as it's a modal object.
Are you setting the focus of the first error-state control before displaying
the messagebox, or after displaying the messagebox?
Al
>> >> Are you using or tried the ErrorProvider control?
>>
[quoted text clipped - 28 lines]
> TIA,
> KK