************************************************** *-- Class: supergrid (d:\vfpclasses\grids.vcx) *-- ParentClass: grid *-- BaseClass: grid *-- My grid aware of form input masks and row change * DEFINE CLASS supergrid AS grid AllowRowSizing = .F. DeleteMark = .F. Height = 59 RowHeight = 15 Width = 206 *-- Current recno() ncurrec = 0 *-- Current record's back color ccurrecbackcolor = (rgb(255,255,0)) *-- Current record's fore color ccurrecforecolor = (rgb(0,0,0)) *-- Warning message when there is incomplete data cwarning = ("You have incomplete data !!!"+chr(13)+"Please fill in required field(s)"+chr(13)+"otherwise record will be restored to its previous state.") PROTECTED lcoldalias lcoldalias = "" *-- Message to represent in case reverting crevertmessage = ("You have incomplete data !!!"+chr(13)+"Revert to previous ?") *-- Decides whether tableupdate(2,.t.,this.recordsource) will be issued when leaving grid or not. ltableupdate = .T. *-- Holds recno of last record when "insert new" attempted PROTECTED nlastvalidrec nlastvalidrec = 0 *-- Keeps activecolumn to use in valid PROTECTED nactivecolumn nactivecolumn = 0 Name = "supergrid" specialcaption = .F. *-- Holds if recordsource is a free table PROTECTED freetable *-- Key field in table ckeyfield = .F. *-- Key expression of key field ckeyexpression = .F. PROTECTED lingrid *-- Array holding controlsources PROTECTED acontrolsources[1] *-- Refresh dynamic colors outside of grid PROCEDURE recchange LOCAL lcAlias WITH This .ncurrec = recno(.recordsource) .refresh ENDWITH ENDPROC *-- Method saving controlsources to a custom array property PROCEDURE savecontrolsource LOCAL ix, oColumn WITH this DIMENSION .acontrolsources[.columncount,2] ix=1 FOR each oColumn in .Columns .acontrolsources[ix,1] = oColumn.controlsource .acontrolsources[ix,2] = oColumn.name ix=ix+1 ENDFOR ENDWITH oColumn = .NULL. ENDPROC *-- Method restoring controlsources from a custom array property PROCEDURE restorecontrolsource LOCAL ix, oColumn WITH this FOR each oColumn in .Columns FOR ix = 1 to alen(.acontrolsources,1) IF .acontrolsources[ix,2] = oColumn.name oColumn.controlsource = .acontrolsources[ix,1] EXIT ENDIF ENDFOR ENDFOR ENDWITH oColumn = .NULL. ENDPROC *-- Returns actual columnindex based on columnorder. PROCEDURE findcolumn LPARAMETERS nColIndex LOCAL ix WITH this FOR ix = 1 to .columncount IF .columns(ix).ColumnOrder = nColIndex RETURN ix ENDIF ENDFOR ENDWITH ENDPROC PROCEDURE When WITH this .lingrid = .T. .lcoldalias = iif(empty(alias()),.recordsource,alias()) SELECT (.recordsource) IF eof(.recordsource) APPEND blank in (.recordsource) ENDIF .ncurrec = recno(.recordsource) .refresh ENDWITH ENDPROC PROCEDURE Valid WITH this IF !empty(.columns(.nactivecolumn).dynamiccurrentcontrol) cCurrentControl = eval(.columns(.nactivecolumn).dynamiccurrentcontrol) ELSE cCurrentControl = .columns(.nactivecolumn).currentcontrol ENDIF WITH evaluate(".columns(.nActiveColumn)."+cCurrentControl) .value = .value && So we can evaluate table ruleexpression ENDWITH .refresh IF !.freetable ; and !empty(dbgetprop(.recordsource,"Table","RuleExpression")) ; and !evaluate(dbgetprop(.recordsource,"Table","RuleExpression")) IF messagebox(.crevertmessage,4+16,"") = 6 TABLEREVERT(.f.,.recordsource) ELSE RETURN .f. ENDIF ENDIF .lingrid = .f. IF .ltableupdate TABLEUPDATE(2,.t.,.recordsource) ENDIF IF eof(.recordsource) and .nlastvalidrec # 0 and .nlastvalidrec <= reccount(.recordsource) lcRecSource = .recordsource .recordsource = "" GO .nlastvalidrec in (lcRecSource) .recordsource = lcRecSource .restorecontrolsource() .recchange() ENDIF SELECT (.lcoldalias) ENDWITH ENDPROC PROCEDURE BeforeRowColChange LPARAMETERS nColIndex llChangingRow = .f. WITH this oColumn = .columns(.findcolumn(nColIndex)) IF lastkey() = 145 && Adding new rec .nlastvalidrec = .ncurrec ENDIF thisform.LockScreen = .lingrid IF mdown() lnBottom = .top+.headerheight+.relativerow * .rowheight lnTop = lnBottom - this.rowheight lnMouseRowPos = mrow(wontop(),3) lnMouseColPos = mcol(wontop(),3) llChangingRow = !(between(lnMouseRowPos,lnTop, lnBottom) ; and between(lnMouseColPos,.left,.left+.width)) ELSE llChangingRow = inlist(lastkey(),24,5,18,3,145,148) ENDIF IF llChangingRow IF !empty(oColumn.dynamiccurrentcontrol) cCurrentControl = eval(oColumn.dynamiccurrentcontrol) ELSE cCurrentControl = oColumn.currentcontrol ENDIF WITH evaluate("oColumn."+cCurrentControl) .value = .value && So we can evaluate table ruleexpression ENDWITH oColumn = .null. IF !empty(dbgetprop(.recordsource,"Table","RuleExpression")) ; and !evaluate(dbgetprop(.recordsource,"Table","RuleExpression")) thisform.LockScreen = .F. IF messagebox(.crevertmessage,4+16,"") = 6 TABLEREVERT(.f.,.recordsource) .recchange() ELSE NODEFAULT ENDIF ENDIF ENDIF ENDWITH ENDPROC PROCEDURE Init SET notify off WITH this .freetable = empty(cursorgetprop("Database",.recordsource)) IF !.freetable IF !dbc()=cursorgetprop("Database",.recordsource) OPEN database (cursorgetprop("Database",.recordsource)) ENDIF IF !this.specialcaption && Default .f. FOR each oColumn in .columns FOR each oControl in oColumn.controls WITH oControl IF upper(oColumn.controlsource) # "RECNO()" ; and inlist(.baseclass,"Textbox","Spinner") .inputmask = dbgetprop(.controlsource,"Field","Inputmask") .format = dbgetprop(.controlsource,"Field","Format") IF .baseclass="Textbox" and !empty(.inputmask) oColumn.sparse = .f. ENDIF ENDIF IF .baseclass="Header" IF upper(oColumn.controlsource) = "RECNO()" .caption = "S.N." && Turkish header for Rec# ELSE tcCaption = dbgetprop(oColumn.controlsource,"Field","Caption") .caption = iif(empty(tcCaption),.caption,tcCaption) ENDIF ENDIF ENDWITH ENDFOR ENDFOR ENDIF ENDIF IF !empty(.recordsource) .savecontrolsource() .ncurrec = recno(.recordsource) .setall("DynamicBackColor", "IIF(RecNo(This.RecordSource) = This.nCurRec," + ; str(.ccurrecbackcolor)+","+str(.backcolor)+")", "Column") .setall("DynamicForeColor", "IIF(RecNo(This.RecordSource) = This.nCurRec," + ; str(.ccurrecforecolor)+","+str(.forecolor)+")", "Column") ENDIF .setall("DisabledForeColor", rgb(0,0,0), "Textbox") .setall("DisabledBackColor", rgb(192,192,192), "Textbox") .nactivecolumn = .findcolumn(1) ENDWITH ENDPROC PROCEDURE AfterRowColChange LPARAMETERS nColIndex WITH this .allowaddnew = .f. IF lastkey() = 145 and iif(.freetable,.t.,; !(!empty(dbgetprop(.recordsource,"Table","RuleExpression")) ; and !evaluate(dbgetprop(.recordsource,"Table","RuleExpression")))) GO bottom in (.recordsource) .allowaddnew = .t. KEYBOARD "{DNARROW}" .refresh ENDIF IF !empty(.ckeyfield) IF empty(eval(.ckeyfield)) REPLACE (.ckeyfield) with eval(.ckeyexpression) ENDIF ENDIF .ncurrec = recno(.RecordSource) thisform.LockScreen = .F. IF !.lingrid .refresh() ENDIF .nactivecolumn = .findcolumn(.ActiveColumn) ENDWITH ENDPROC ENDDEFINE * *-- EndDefine: supergrid **************************************************Cetin