Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The Return of Stupid Programmer Tricks...
Message
General information
Forum:
Visual FoxPro
Category:
Other
Title:
The Return of Stupid Programmer Tricks...
Miscellaneous
Thread ID:
00717946
Message ID:
00717946
Views:
50
...or another use for Foxtools

A recent request required that I build a grid that when a header was clicked it would sort the underlying table by that field. Naturally, I first sub-classed a form and grid for this purpose. I next created a new form based on the classes and dropped the remote view into it. Now the only way I know of to get this to work is to insert code into the click event of the header. This meant using the grid builder to make the appropriate assignments so that the header objects where available. I'm sure that anyone who has done this would agree that it's a real PITA.

Since I knew, however, that it's possible to open a form and specify an object method/event code window to open as well, I thought it might be possible to programmatically do this sort of thing. It is. The code below represents a way to do this. Note: This requires that the Foxtools.fll library be set prior to calling this prg. One other thing to note was that the grid's position on the form is 0, 0, so it may be necessary to modify the code to achieve the desired result. Further, this wasn't something that I spent a lot of time with, so there may be a better solution to getting the column object reference.
* Program: HeaderClick.prg
* Author: George Tasker
* Date: October 23, 2002 - 1:50 PM
* Purpose: Inserts a command in the click
* event of a grid's header objects

LPARAMETERS tcFileName, tcClickEvent

* tcFileName - The form file containing the grid
*
* tcClickEvent - The code to insert
*

LOCAL lcfilename, lccaption, lnwhandle, a_objs,;
  lntop, lnleft, lni, lncolumns, lcname, lcmethod
_CLIPTEXT = tcClickEvent + CHR(13) + CHR(10)
DIMENSION a_objs[1]
IF UPPER(JUSTEXT(tcFileName)) = 'SCX'
  lcfilename = JUSTFNAME(tcFileName)
  lccaption = 'Form Designer - ' + LOWER(lcfilename)
  MODIFY FORM (tcFileName) NOWAIT 
  lnwhandle = _WFindTitl(lccaption)
  lntop = _WTopP(lnwhandle) + (SYSMETRIC(9) * 2) + (SYSMETRIC(4) * 2) + 14
  lnleft = _WLeftP(lnwhandle) + (SYSMETRIC(4) * 2) + 14
  ACTIVATE WINDOW (lccaption)
  MOUSE CLICK AT lntop, lnleft PIXELS WINDOW (lccaption)
  WAIT WINDOW "" TIMEOUT 1 && Required to get the reference to the grid
  IF AMOUSEOBJ(a_objs) > 0
    IF a_objs[1].BaseClass = 'Column'
      lncolumns = a_objs[1].Parent.ColumnCount
      lcname = a_objs[1].Parent.Name + '.Column'
      FOR lni = 1 TO lncolumns
        lcmethod = lcname + TRANSFORM(lni) + '.Header1.Click'
        MODIFY FORM (tcFileName) NOWAIT METHOD &lcmethod 
        ACTIVATE WINDOW 'Header1.Click'
        lnwhandle = _WFindTitl('Header1.Click')
        = _WSelect(lnwhandle)
        = _EdPaste(lnwhandle)
        = _WClose(lnwhandle)
        DO WHILE _WOnTop() = lnwhandle
        ENDDO
      NEXT 
    ENDIF 
  ENDIF 
ENDIF 
RETURN
Note, however, I did try other means of trying paste the code into the method/event code window, including KEYBOARD...and SYS(1500).
George

Ubi caritas et amor, deus ibi est
Next
Reply
Map
View

Click here to load this message in the networking platform