Microsoft KB Archive/146222

= How to Use Grid MouseDown Code to Prevent Row/Partition Resize =

Article ID: 146222

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition

-



This article was previously published under Q146222



SUMMARY
There are no Grid properties that can be used to disable the ability to use the mouse to resize the Grid HeaderHeight and RowHeight or move the Partition Slider. However, code can be placed in the user procedure associated with the Grid MouseDown event to prevent any of the following actions being made with the mouse:


 * Resizing the Grid HeaderHeight
 * Resizing the Grid RowHeight
 * Moving the Partition Slider



MORE INFORMATION
To cause the mouse action to be ignored at certain times, a NODEFAULT is conditionally executed in the Grid MouseDown code depending on the mouse coordinates. This effectively prevents access to the three previously listed properties. The following code example is designed for a grid that can be used in a form, on a page of a pageframe or within a container, regardless of nesting level.

Place the following code in the procedure associated with the MouseDown event for the grid. ****** Start of Grid MouseDown


 * If the grid is on a form (not in a container or pageframe),
 * this section may be omitted. It iterates through
 * object nesting level for all objects above the grid in the
 * hierarchy and makes necessary adjustments to nXCoord and
 * nYCoord. This allows the NODEFAULT to be called at the appropriate
 * time regardless of whether the grid is in a container, page in
 * a pageframe, or a combination that contains several layers.
 * a pageframe, or a combination that contains several layers.

LOCAL cObjlist, nTopTotal, nLeftTotal

cObjlist = '' nLeftTotal = 0 nTopTotal = 0

cObjlist = SYS(1272,this)       && Get object hierarchy for grid IF TYPE('ThisFormSet') = 'O'    && In a Formset? * If so, remove Formset from object list cObjlist=SUBSTR(cObjlist,AT('.',cObjlist)+1) ENDIF

cObjlist='thisform' + SUBSTR(cObjlist,AT('.',cObjlist), ; RAT('.',cObjlist) - AT('.',cObjlist))
 * Strip off grid name and replace form name with 'thisform'

IF !'thisform'==(cObjlist)  && Something more than thisform in hierarchy? FOR i=1 TO OCCURS('.',cObjlist) && Number of '.'s = depth of hierarchy IF TYPE("EVAL(cObjList+'.left')")='N'  && Does Obj have Left property? nLeftTotal = nLeftTotal+EVAL(cObjlist+'.left') + ; IIF('3.10' $ OS(1) OR 'NT' $ OS(1),1,0) && Add it in    ENDIF IF TYPE("EVAL(cObjList+'.top')")='N'   && Does Obj have Top property? nTopTotal=nTopTotal+EVAL(cObjlist+'.top') && Add it in    ENDIF IF EVAL(cObjlist+'.baseclass')='PageFrame' && Is object a PageFrame? IF EVAL(cObjlist+'.tabs')=.T. && Does PageFrame have Tabs? nTopTotal=nTopTotal+24 + ; IIF('3.10' $ OS(1) OR 'NT' $ OS(1),2,0)  && Add in Tab height ELSE nTopTotal=nTopTotal + ; EVAL(cObjlist+'.borderwidth') + ; IIF(EVAL(cObjlist+'.SpecialEffect')<2,1,0) nLeftTotal=nLeftTotal+EVAL(cObjlist+'.borderwidth') ENDIF nLeftTotal=nLeftTotal+1+ IIF('3.10' $OS(1) OR 'NT' $ OS(1),1,0) ENDIF * Pare last object from list cObjlist=SUBSTR(cObjlist,1,RAT('.',cObjlist)-1) ENDFOR ENDIF

nXCoord=nXCoord-nLeftTotal  && Compensate nX- and nYCoord for top and left nYCoord=nYCoord-nTopTotal   && of all containers that hold the Grid

WITH this * Each of these checks the position of the mouse when the MouseDown * is called. If the position is where the click should be ignored, * NODEFAULT is issued.
 * End of section to omit if grid is directly on form
 * End of section to omit if grid is directly on form

* This makes rows not resizable

IF nXCoord < .partition + .Left + 20 AND ; nYCoord > .Top + .HeaderHeight + .RowHeight - 5 AND ; nYCoord < .Top + .HeaderHeight + .RowHeight + 7 NODEFAULT ENDIF

* This makes header not resizable

IF nXCoord < .partition + .Left + 20 AND ; nYCoord > .Top + .HeaderHeight - 5 AND ; nYCoord < .Top + .HeaderHeight + 7 NODEFAULT ENDIF

* This makes partition not moveable

IF MOD(.ScrollBars,2) = 1      && Check for horizontal scrollbar IF nXCoord < .partition + .Left + 6 AND ; nXCoord >= .partition + .Left AND ; nYCoord > .Top + .Height - 19 NODEFAULT ENDIF ENDIF

ENDWITH