oForm = Createobject('myForm') With oForm .AddObject('myGrid','myGrid') .AddObject('myButton','myButton') .MyButton.Visible = .T. With .myGrid .Top=oForm.MyButton.Height + 10 .Left = 10 .Height = oForm.Height - (.Top+20) .Width = oForm.Width - 20 .SetSource('products') .Visible = .T. Endwith .Show Endwith Read Events Define Class myForm As Form Height = 400 Width = 600 ShowTips = .T. DataSession=2 Procedure Load Use products In 0 Use employee In 0 Endproc Procedure QueryUnload Clear Events Endproc Enddefine Define Class MyButton As CommandButton Caption = 'Switch source' Procedure Click With Thisform.myGrid .SetSource(Iif(Upper(.RecordSource)='EMPLOYEE','products','employee')) Endwith Endproc Enddefine Define Class myGrid As Grid DeleteMark = .F. ReadOnly = .T. RecordMark = .F. ScrollBars = 3 SplitBar = .F. Highlight = .F. HighlightRow = .F. Name = "grdMyGrid" Procedure AddColumn Lparameters nIndex, cAlias, cField, cCaption Nodefault This.AddObject("clm"+cField,"myColumn", cAlias+"."+cField,nIndex) Endproc Procedure SetSource Lparameters tcRecordsource With This .RecordSource = '' .RecordSource = tcRecordsource .ColumnCount = -1 For ix = 1 To Fcount(tcRecordsource) .AddColumn(ix, tcRecordsource,Field(ix,tcRecordsource)) Endfor .SetAll('Visible',.T.) .SetFocus() Endwith Endproc Enddefine Define Class myColumn As Column Resizable = .F. Movable = .F. Procedure Init Lparameters cControlSource, nIndex With This .ControlSource = cControlSource .ColumnOrder = nIndex .Header1.Caption = Justext(cControlSource) If Type(cControlSource)='L' .AddObject("myControl","myGridChkBox") Else .AddObject("myControl","myGridTxtBox") Endif .CurrentControl = "myControl" .Sparse = .F. Endwith Endproc Procedure Resize This.myControl.Resize Endproc Procedure MouseMove Lparameters nButton, nShift, nXCoord, nYCoord With This.Parent lnActiveRow = Ceiling( ; ( nYCoord - (.Top + .HeaderHeight) ) / .RowHeight ) lnActivecol = This.ColumnOrder - This.Parent.LeftColumn + 1 .ActivateCell(lnActiveRow,lnActivecol) Endwith With This If Type(.ControlSource)$'CM' .myControl.ToolTipText = ; iif(Type(.ControlSource)='C', Eval(.ControlSource),; iif(Type(.ControlSource)='M', Mline(Eval(.ControlSource),1),'')) Endif Endwith Endproc Enddefine Define Class myGridChkBox As Container Width = 14 Height = 17 BackStyle = 0 BorderWidth = 0 Name = "grdcheckbox" Add Object check1 As Checkbox With ; Top = 0, ; Left = 0, ; Height = 17, ; Width = 13, ; BackStyle = 0, ; Caption = "", ; Name = "Check1" Procedure Init With This .check1.ControlSource = .Parent.ControlSource .Resize() Endwith Endproc Procedure Resize With This.check1 .Left = (This.Parent.Width - .Width)/2 Endwith Endproc Enddefine Define Class myGridTxtBox As TextBox Name = "Text1" BorderStyle = 0 MousePointer = 1 EnddefineCetin