grewegreg
IS-IT--Management
- Apr 1, 2007
- 23
Folks,
I have created a grid with some custom properties and methods. Whenever I drop the grid onto a form or inside another class, the properties and methods of the grid work just fine, except using the scrollbars. Even though the scrollbars are set to 3 (Both), they act as if they are disabled. I can scroll the grid using the arrow, page up or page down keys, but not the scroll bars. Changing the ReadOnly property does not seem to have any affect either.
I have pasted the code below, any suggestions would be greatly appreciated... Thanks in advance.
Greg Grewe
Diamond Consulting, LLC
I have created a grid with some custom properties and methods. Whenever I drop the grid onto a form or inside another class, the properties and methods of the grid work just fine, except using the scrollbars. Even though the scrollbars are set to 3 (Both), they act as if they are disabled. I can scroll the grid using the arrow, page up or page down keys, but not the scroll bars. Changing the ReadOnly property does not seem to have any affect either.
I have pasted the code below, any suggestions would be greatly appreciated... Thanks in advance.
Code:
**************************************************
*-- Class: base_grid (c:\data\foxpro\base classes\base_classes.vcx)
*-- ParentClass: grid
*-- BaseClass: grid
*-- Time Stamp: 05/20/07 04:31:07 PM
*
#INCLUDE "c:\data\foxpro\bin\foxpro.h"
*
DEFINE CLASS base_grid AS grid
ColumnCount = 5
DeleteMark = .F.
HeaderHeight = 30
Height = 265
ReadOnly = .T.
Width = 410
HighlightBackColor = RGB(0,128,0)
HighlightStyle = 2
AllowCellSelection = .F.
*-- XML Metadata for customizable properties
_memberdata = [<VFPData><memberdata name="tooltiptext" type="Property" favorites="True"/><memberdata name="statusbartext" type="Property" favorites="True"/></VFPData>]
ro_display_sub_form = .F.
rc_parenttable = "THISFORM.rc_MasterAlias"
Name = "base_grid"
Column1.Alignment = 2
Column1.ReadOnly = .F.
Column1.Name = "Column1"
Column2.Alignment = 2
Column2.ReadOnly = .T.
Column2.Name = "Column2"
Column3.Alignment = 2
Column3.ReadOnly = .T.
Column3.Name = "Column3"
Column4.Alignment = 2
Column4.ReadOnly = .T.
Column4.Name = "Column4"
Column5.Alignment = 2
Column5.ReadOnly = .T.
Column5.Name = "Column5"
ADD OBJECT base_grid.column1.header1 AS header WITH ;
Alignment = 2, ;
Caption = "Header1", ;
Name = "Header1"
ADD OBJECT base_grid.column1.text1 AS textbox WITH ;
Alignment = 2, ;
BorderStyle = 0, ;
Margin = 0, ;
ReadOnly = .F., ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT base_grid.column2.header1 AS header WITH ;
Alignment = 2, ;
Caption = "Header1", ;
Name = "Header1"
ADD OBJECT base_grid.column2.text1 AS textbox WITH ;
Alignment = 2, ;
BorderStyle = 0, ;
Margin = 0, ;
ReadOnly = .T., ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT base_grid.column3.header1 AS header WITH ;
Alignment = 2, ;
Caption = "Header1", ;
Name = "Header1"
ADD OBJECT base_grid.column3.text1 AS textbox WITH ;
Alignment = 2, ;
BorderStyle = 0, ;
Margin = 0, ;
ReadOnly = .T., ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT base_grid.column4.header1 AS header WITH ;
Alignment = 2, ;
Caption = "Header1", ;
Name = "Header1"
ADD OBJECT base_grid.column4.text1 AS textbox WITH ;
Alignment = 2, ;
BorderStyle = 0, ;
Margin = 0, ;
ReadOnly = .T., ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT base_grid.column5.header1 AS header WITH ;
Alignment = 2, ;
Caption = "Header1", ;
Name = "Header1"
ADD OBJECT base_grid.column5.text1 AS textbox WITH ;
Alignment = 2, ;
BorderStyle = 0, ;
Margin = 0, ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
PROCEDURE m_sort_grid
LOCAL lcSafety AS Character, lcField AS Character, lcString AS Character, ;
lcAlias AS Character, loColumn AS Object, nView_Out AS Integer, ;
nWhere_Out AS Integer, nRelRow_Out AS Integer, nRelCol_Out AS Integer, ;
nXCoord_In AS Integer, nYCoord_In AS Integer, lnBuffering, lcSortOrder AS Character, ;
i as Integer, loHeader AS Object
nXCoord_In = MCOL(WONTOP(),3)
nYCoord_In = MROW(WONTOP(),3)
STORE 0 TO nWhere_Out, nRelRow_Out, nRelCol_Out, nView_Out
IF THIS.GridHitTest(nXCoord_In, nYCoord_In, @nWhere_Out, @nRelRow_Out, @nRelCol_Out)
loColumn = "THIS.Column" + ALLTRIM(STR(nRelCol_Out))
loColumn = EVALUATE(loColumn)
lcAlias = UPPER(THIS.RecordSource)
lcString = UPPER(loColumn.ControlSource)
lcField = STRTRAN(lcString, lcAlias + ".", "")
lcString = EVALUATE(lcString)
SELECT(lcAlias)
lnBuffering = CURSORGETPROP("Buffering", lcAlias)
IF CURSORSETPROP("Buffering", 3, lcAlias)
lcSafety = SET('SAFETY')
SET SAFETY OFF
*
DO CASE
CASE VARTYPE(lcString) = "C"
lcSortOrder = "INDEX ON ALLTRIM(" + lcField + ")"
CASE VARTYPE(lcString) = "N" OR VARTYPE(lcString) = "Y" OR VARTYPE(lcString) = "D" ;
OR VARTYPE(lcString) = "T" OR VARTYPE(lcString) = "L"
lcSortOrder = "INDEX ON " + lcField
CASE VARTYPE(lcString) = "Q" OR VARTYPE(lcString) = "G" OR VARTYPE(lcString) = "O" ;
OR VARTYPE(lcString) = "X" OR VARTYPE(lcString) = "U"
lcSortOrder = loColumn.Header1.Caption
ENDCASE
*
*!* Set every column, except the one selected, to no picture and no sort
*
FOR i = 1 TO THIS.ColumnCount
IF i <> nRelCol_Out
loHeader = "THIS.Column" + ALLTRIM(STR(i))
loHeader = EVALUATE(loHeader)
loHeader.Header1.Picture = ''
loHeader.Header1.rn_Sorted = 0
ENDIF &&& i <> nRelCol_Out
ENDFOR &&& i = 1 TO THIS.ColumnCount
*
IF loColumn.Header1.rn_Sorted = 0 OR loColumn.Header1.rn_Sorted = 2
&&& Nothing Set, make Ascending OR Descending, change to Ascending
loColumn.Header1.Picture = "ARW08UP.ICO"
lcSortOrder = lcSortOrder + " TAG Key ASCENDING"
loColumn.Header1.rn_Sorted = 1
ELSE
&&& Ascending, change to Descending
loColumn.Header1.Picture = "ARW08DN.ICO"
lcSortOrder = lcSortOrder + " TAG Key DESCENDING"
loColumn.Header1.rn_Sorted = 2
ENDIF &&& loColumn.Header1.rn_Sorted = 0 OR loColumn.Header1.rn_Sorted = 2
*
IF LEFT(lcSortOrder,5) = "INDEX"
&lcSortOrder
ELSE
=MESSAGEBOX('I am sorry, but I can not sort this display by the field type "' + ;
ALLTRIM(lcSortOrder) + '", please select a different column!', 0, "Problem Sorting Display...")
ENDIF &&& LEFT(lcSortOrder,5) = "INDEX"
*
GO TOP
SET SAFETY &lcSafety
=CURSORSETPROP("Buffering", lnBuffering, lcAlias)
ENDIF
THIS.Refresh(.T.)
SELECT(THISFORM.rc_MasterAlias)
ELSE
ENDIF
ENDPROC
PROCEDURE m_get_backcolor
LPARAMETERS pcCheckColor
STORE .F. TO THIS.HighlightRow, THIS.Highlight
DO CASE
*!* CASE RECNO(THIS.RecordSource) = THISFORM.MasterId
*!* STORE THISFORM.BackColor TO pcCheckColor
*!* &&... highlight colour RGB(...)
*!* RETURN &pcCheckColor
CASE pcCheckColor = ' '
RETURN RGB(255,0,255) &&... white - no category
OTHERWISE
STORE ALLTRIM(pcCheckColor) TO pcCheckColor
&&... colour code from record
RETURN &pcCheckColor
ENDCASE
ENDPROC
PROCEDURE DblClick
LPARAMETERS plAdd, plMasterId
LOCAL loColumn AS Object, loFormName AS Object, lnMasterId AS Integer
*
IF !EMPTY(THIS.ro_Display_Sub_Form)
IF VARTYPE(plAdd) = "L" AND plAdd &&& Add
IF EMPTY(plMasterId)
lnMasterId = THISFORM.txtMasterId.Value
ELSE
lnMasterId = plMasterId
ENDIF &&& EMPTY(plMasterId)
ELSE &&& Edit
SELECT(THIS.RecordSource)
lnMasterId = MasterId
SELECT(THISFORM.rc_MasterAlias)
ENDIF
*
loFormName = CREATEOBJECT(THIS.ro_Display_Sub_Form, THISFORM, plAdd, lnMasterId) &&& THISFORM.DataSessionId)
IF VARTYPE(loFormName) = "O"
loFormName.Show()
ENDIF
ELSE
THIS.Parent.cmdEdit.Click()
ENDIF
ENDPROC
PROCEDURE Refresh
LPARAMETERS llRequery
IF TXNLEVEL() = 0 AND !llRequery
REQUERY( THIS.RecordSource )
ENDIF
*
FOR EACH loColumn IN THIS.Columns
loColumn.Width = VAL(loColumn.Tag)
ENDFOR
ENDPROC
PROCEDURE Init
LOCAL loColumn AS Object, loControl AS Object
FOR EACH loColumn IN THIS.Columns
loColumn.Alignment = 2
loColumn.Tag = ALLTRIM(STR(loColumn.Width))
IF !EMPTY(loColumn.Comment)
STORE loColumn.Comment TO loColumn.Header1.Caption
ENDIF
*
FOR EACH loControl IN loColumn.Controls
DO CASE
CASE LOWER( loControl.BaseClass ) = 'textbox'
BINDEVENT( loControl, 'DblClick', THIS, 'DblClick' )
IF loColumn.Comment = 'LEFT'
loColumn.Alignment = 0
ELSE
loControl.Alignment = 2
ENDIF
CASE LOWER( loControl.BaseClass ) = 'header'
BINDEVENT( loControl, 'Click', THIS, 'm_Sort_Grid')
loControl.Alignment = 2
loControl.AddProperty("rn_Sorted", 0)
OTHERWISE
ENDCASE
ENDFOR &&& EACH loControl IN loColumn.Controls
ENDFOR &&& EACH loColumn IN THIS.Columns
ENDPROC
PROCEDURE text1.DblClick
THIS.Parent.Parent.m_DIsplay_sub_forms()
ENDPROC
ENDDEFINE
*
*-- EndDefine: base_grid
**************************************************
Greg Grewe
Diamond Consulting, LLC