Out-Gridview: run scripts when either Cancel or OK buttons pressed?

Powershell V5
I need to run a different script depending on which of the OK or Cancel buttons are clicked. Is there a simple solution please?

Can you share what you have so far ? Do you mean run script 1 if ok is clicked and run script 2 if cancel is clicked ? or are their multiple ok and cancel buttons on a form ?

See here for example of an on_click event

I am using a standard Out-Gridview (not WPF) and need to run 1 script when OK is clicked and another for the Cancel button. I can find no information anywhere about this.

I guess you could do something like this:

$Selected = Get-Process | Out-GridView -PassThru
if($null -eq $Selected) {
    # Cancel was pressed
    # Run cancel script
else {
    # OK was pressed, $Selected contains what was chosen
    # Run OK script

It works nicely and exits with the Cancel button or the X at the top. Thank you, Sir.