Dynamic grid set selection



I have a view that connects F4801,F3112,F4101 so some of the rows are duplicate except for the F3112 values (specifically the OPSQ column, which is the status) I have written a BSFN that if you pass the doco in it gives you the max OPSQ back. What I wanted to do was run through the grid and dynamically set the selection to only return the OPST values between 10 and 20, and then the max OPSQ per doco. I tried putting this in a button but it doesn't work. Any ideas on the best way to do this?

Thanks in advance!

Get Max Grid Rows(FC Grid, VA evt_MaxGridRows_INT01)
VA frm_SelectedRowInt = 1
While VA frm_SelectedRowInt is less than VA evt_MaxGridRows_INT01
Get Grid Row(FC Grid, VA frm_SelectedRowInt)
Find Max OPSQ for each DOCO
Set Selection(FC Grid, "F3112", "OPST", <Greater Than or Equal To>, "10", <And>)
Set Selection(FC Grid, "F3112", "OPST", <Less Than or Equal To>, "20", <And>)
Set Selection(FC Grid, "F3112", "OPSQ", <Equal To>, VA frm_SequenceNoOperations_OPSQ, <And>)
VA frm_SelectedRowInt = [VA frm_SelectedRowInt]+1
End While

Try using the Event Write Grid Line - Before and prevent the line from being written to the grid. I think there is a system function to do that.