Highlighted
Absent Member.
Absent Member.
1913 views

Overriding a 'Leave' event

Jump to solution

We have certain fields on forms designated with a 'Leave' event so that in once the user leaves the field the field is validated.

In the event that the field is deemed to be in error focus is returned to the field and the user then re-enters the data.

I have a problem in that the user wishes to leave the form by way of an Exit button. Clicking on the button when a field is in error though generates a 'leave' event for the incorrect field even though there is a 'Click' event attached to the Exit button which says 'Get Out of form' and we go round in a circle with the user continually being presented with the field in error in focus instead of the 'Exit button' event being done.

How do I overide one event with another so that the Exit button 'Click' event supercedes the 'Leave' event of the data field on the form? 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Overriding a 'Leave' event

Jump to solution

Take a look at the KB article here as I believe it applies to your situation.

The demo in the article doesn't use the Leave event but uses the Validating event instead as the textbox has its CausesValidation property set to true.

Thanks.

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Overriding a 'Leave' event

Jump to solution

Take a look at the KB article here as I believe it applies to your situation.

The demo in the article doesn't use the Leave event but uses the Validating event instead as the textbox has its CausesValidation property set to true.

Thanks.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Overriding a 'Leave' event

Jump to solution

Hi Chris,

I've cut & pasted the code into a new Windows Form app, created the correct 'validating event' and my code reads like so...

      class-id Override.Form1 is partial

                inherits type System.Windows.Forms.Form.

      working-storage section.

      method-id NEW.

      procedure division.

          invoke self::InitializeComponent

          invoke textBox1::Focus

          goback.

      end method.

      method-id IsFormClosing public.

      local-storage section.

      78 WMCLOSE value "WmClose".

      01 stackTrace type System.Diagnostics.StackTrace.

      01 stframes type System.Diagnostics.StackFrame occurs any.

      01 MethodName type System.Reflection.MethodBase.

      procedure division returning FormIsClosing as condition-value.

         set FormIsClosing to false

         set stackTrace to new System.Diagnostics.StackTrace

         set stframes to stackTrace::GetFrames

         perform varying sf as type System.Diagnostics.StackFrame thru stframes

            set MethodName to sf::GetMethod

            if MethodName::Name = WMCLOSE

               set FormIsClosing to true

               exit perform

            end-if

         end-perform

         goback.

      end method.

      method-id textBox1_Validating final private.

      procedure division using by value sender as object e as type System.ComponentModel.CancelEventArgs.

           if self::IsFormClosing = false

                 if textBox1::Text = "Yes" or "No"

                    continue

                 else

                    invoke type MessageBox::Show("Must be Yes or No")

                    set e::Cancel to true

                 end-if

              end-if.

      end method.

      method-id buttonCancel_Click final private.

      procedure division using by value sender as object e as type System.EventArgs.

          invoke self::Close

      end method.

      end class.

I think you'll find its EXACTLY the same as the proposed solution.

Doesn't seem to work.

I still get the message box appearing DESPITE me pressing the Cancel button.

Can you check this please?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Overriding a 'Leave' event

Jump to solution

There is an attachment on the article which contains a full solution and project zipped up.

Please download this and step through it with the debugger and compare the code execution path with yours.

Perhaps one of the properties for the controls has not been set properly?

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Overriding a 'Leave' event

Jump to solution

Sorted.

The 'Exit Button' on screen should be set to CausesValidation=False in the button properties!

Easy when you know how!!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.