7 Replies Latest reply on Aug 28, 2016 1:38 PM by fabino

    Centering A Record In A List View



      Centering A Record In A List View


           Given a specific RecordNumber, I wish to write a script that will always center any selected RecordNumber in a list view of very many records. I have a index layout with buttons on the titles. When selected, the buttons open a Form view of the title related contents. All works great. 

           On returning from the Form view to the List view, I need to center the particular selected RecordNumber in the displayed list of records. Not default to top or bottom. "Go to Record/Request/Page" selects the record but will not scroll the page.

           My return script, finds all, sorts and preps window size, then ends with a "Go to Record/Request/Page" calculation using the selected RecordNumber as the calculation.

           Performance is unstable, sometimes it works but leaves the selected record at the last record in the displayed list. Sometimes it goes to the top of page and selection is off screen all together?

           Tried "Scroll Window". This function appears to be useless. Does not work for any of the caned "Home/End/PageUp/PageDown/To Selection" values. How do I specify a "To Selection" value.  "Set Selection" does not appear to be a valid approach.

           Tried adding 15 to value of last record visited, workes sometimes but leaves the wrong record selected. Adding a second line to go to the correct record moves the display back to the bottom again

           I am at a loss hear and would appreciate any suggestions anyone may have


        • 1. Re: Centering A Record In A List View

               Since the current record could be at or near the top of your found set or could be near or at the bottom of your found set, you won't always be able to center the current record, but when that is not the case, the following script should succeed in centering the record vertically:

               Set Variable [$RecordNumber ; get ( CurrentRecordNumber ) ]
               Go to record number [no dialog ; Get ( FoundCount ) ] ---> Make last record in found set the current record, scrolls window to the bottom
               Go to Record Number [ No Dialog ; Max ( $RecordNumber - (Total Rows per screen / 2 ) ; 1 ) ]
               Go to Record Number [ No Dialog ; $RecordNumber ]

               If your list view can show up to 25 records at a time, that would make the next to last step:

               Go to Record Number [ No Dialog ; Max ( $RecordNumber - 12 ; 1 ) ]

               Note that this only works perfectly for records that aren't records near the top or bottom of the found set nor with layout designs where the window resizes to different heights on different monitors. More sophisticated variations could use a get function to detect the window height and use it to calculate the value needed in step 3.

          • 2. Re: Centering A Record In A List View

                 Thanks for the input. Understand the top and bottom records cannot be centered. That is not a problem.

                 My process which is essentially what you describe except I was not forcing the record pointer to the bottom of the stack. Adding this step stabalized the script perfomance and it now works like a charm - except - it still leaves the active record pointer setting at the last record in the visible list. I am matching a global Last_Record_Visited field to the actual Record_Number field in a Conditional Formatting statement to highlight the functional index record and the record I need to return to and place near the center of the list (when possible). The active record pointer is always the offset number of records away.  Very dangerous situation since the user may damage this record thinking they are working in the highlited record. 

                 Any suggestions on moving the active record pointer back to the Last_Record_Visited value without the list moving?

            • 3. Re: Centering A Record In A List View

                   I tested my script before I posted it. It centers on the current record when possible.

              • 4. Re: Centering A Record In A List View

                     Thanks for the assist. Apparently we are not working the same problem. My wife has a problem understanding me alsoangry

                     The set back approach was the frist one I tested and I have tested this approach repeatedly. I do not get the results you describe.

                     If I leave the Record Pointer in the offset, the list centers (exact count asside).  But, when I execute even one back step, the list pointer remains at the bottom of the list and the selected record moves down to meet the record pointer - (ignoring the top/bottom extremes).

                     I am working with 120 test records starting at 60 so the extreams are not an issue.


                • 5. Re: Centering A Record In A List View

                       I have a demonstration file that I could post hear but being new to this interface, I cannot find the attach file function. 

                       In my example file the Go to Record Number [ No Dialog ; Pervious ] walks the visible list down to where it is setting rather than walking up the visible list. My structure is a bit more complex than yours but I can't find anything in my scripts or layouts that would explain the different performance.

                  Can you explain how I can attach a runtime or source file to this system?


                  • 6. Re: Centering A Record In A List View

                         I'd look for a script trigger that your script may be tripping when it executes. That triggered script might interfere with the results of this "centering" script.

                         To share a file via this forum, upload the file to a sharing site such as Drop Box and then post the download link here.

                    • 7. Re: Centering A Record In A List View

                      Thanks for the tip philmodjink,


                      I am using FMPA 13 and your script works but only if I add a script pause after each goto record command.

                      If I have the script run without any pause, it will always move the selected record as the last line in the list.

                      If I follow the steps by adding a pause, the list is vertically centered on the record selected.

                      Is that normal?


                      I have it working by adding a pause of 0,01 seconds after each step.