*gridonthefly.prg Define class myGrid as grid DeleteMark = .F. ReadOnly = .T. RecordMark = .F. ScrollBars = 2 Name = "grdMyGrid" Procedure addcolumn Lparameters nIndex, cAlias, cField Nodefault This.addobject("clm"+cField,"myColumn", cAlias+"."+cField,nIndex) Endproc Procedure init Lparameters tcRecordsource With this .Columncount = -1 .recordsource = tcRecordsource nOldColCount = .columncount For ix = 1 to fcount(tcRecordsource) .AddColumn(ix, tcRecordsource,field(ix,tcRecordsource)) Endfor For ix = nOldColCount to 1 step -1 .RemoveObject(.Columns(ix).name) Endfor Endwith Endproc Enddefine Define class myColumn as column Resizable = .F. Movable = .F. Procedure init Lparameters cControlSource, nIndex With this .controlsource = cControlSource .ColumnOrder = nIndex .RemoveObject('Header1') .Addobject('myHeader','myHeader') .AddObject("myText","myGridTxtBox") .CurrentControl = "myText" .Sparse = .F. Endwith Endproc Procedure MouseMove Lparameters nButton, nShift, nXCoord, nYCoord With this.Parent lnActiveRow = ceiling( ; ( nYCoord - (.top + .headerheight) ) / .rowheight ) .ActivateCell(lnActiveRow,3) Endwith This.setfocus() This.myText.Tooltiptext = iif(type(this.controlsource)='C',this.myText.Value,'') Endproc Enddefine Define class myGridTxtBox as TextBox BackColor = rgb(0,0,255) ForeColor = rgb(255,255,255) SelectedBackColor = rgb(255,0,0) SelectedForeColor = rgb(255,255,0) Name = "Text1" Procedure init This.BorderStyle = 0 Endproc Procedure click This.setfocus() Endproc Enddefine Define class myHeader as Header BackColor = 0 ForeColor = rgb(255,255,0) Procedure init This.Caption = this.parent.controlsource Endproc EnddefineCalling sample :
set procedure to gridonthefly.prg additive thisform.Addobject('myGrid','myGrid','Employee') with thisform.myGrid .Height = this.top .Width = thisform.width .Visible = .t. endwithCetin