PDA

Click to See Complete Forum and Search --> : Determine if button was clicked...


vbud
Dec 7th, 2006, 11:23 PM
Hi all, i have the following situation on a Windows Mobile 5 device :

I have some validation on the lost focus event of a control. However when the user clicks on the Cancel button, the lost focus event of the above control is triggered before the click event, which is normal i guess, but validation error messages are displayed while the form is closing. Is there a way in the lost focus event or any other work around to determine if the Cancel button was clicked or something so that I can suppress validation messages then? I was checking if the Cancel button had focus to do this but I think its not a very elegant solution. Please note that i'm using C#.

Strider
Dec 8th, 2006, 03:52 AM
if your using Visual Studio 05 have you tried using the causesvalidation property on the controls?

or else maybe create a member variable on the form m_closing as boolean = false
then on the form_closing event set this m_closing = True

then in the lost_Focus event try If Not m_closing Then

Shaggy Hiker
Dec 8th, 2006, 11:16 AM
That'll be tough, because the control loses focus before anything associated with the next control (the cancel button) is fired.

Personally, I really don't like using LostFocus, but that bias comes from desktop systems, and may be totally irrelevant to the smaller PDA etc. programming. The issue with desktop systems was that the event may NEVER fire. On a portable, I'd want to confirm that the event was fired if control was switched to a new programl.

If you find that there is an alternative time to do the validation, that might be the best solution. Otherwise, if the solution you have works, it might be the best way, even if it isn't elegant. The only alternatives I could think of were variants of what you posted.