>oForm = Createobject('myForm') >oForm.Show >Read Events > >Define Class myForm As Form > DataSession = 2 > Width = 450 > Height = 320 > > Procedure Init > This.Newobject('myGrid1','mySorterGrid1','','','crsTest') > With This.myGrid1 > .Top = 10 > .Left = 25 > .Width = 400 > .Height = 300 > .Visible = .T. > Endwith > Endproc > > Procedure Load > Select cust_id, company,contact, ; > 0x7FFFFFFF As sorter, 0x7FFFFFFF As original ; > from customer ; > order By cust_id ; > into Cursor crsTest ; > readwrite > Replace All sorter With Recno(), original With Recno() > Index On sorter Tag sorter > Endproc > > Procedure QueryUnload > Clear Events > 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 > Nodefault > Local lcColName > lcColName = "clm"+cField > This.AddObject(m.lcColName,"myColumn", cAlias+"."+cField,nIndex) > With Evaluate('this.'+m.lcColName) > .Header1.Caption = m.cField > Endwith > 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 > .ColumnCount = nOldColCount > Endwith > Endproc > > Procedure MyDragDrop > Lparameters oSource, nXCoord, nYCoord, nState > Local lnFrom, lnTo > With This > nXCoord_In = Mcol(Wontop(),3) > nYCoord_In = Mrow(Wontop(),3) > Store 0 To nWhere_Out , nRelRow_Out , nRelCol_Out , nView_Out > If .GridHitTest(nXCoord_In, nYCoord_In, ; > @nWhere_Out, @nRelRow_Out, @nRelCol_Out) And nWhere_Out = 3 > lnFrom = Recno() > .ActivateCell(nRelRow_Out, nRelCol_Out) > lnTo = Recno() > .MoveRecord(lnFrom,lnTo) > Endif > Endwith > Endproc > > Procedure MoveRecord > Lparameters tnFrom, tnTo > If tnFrom = tnTo > Return > Endif > Local lnFrom, lnTo > Select (This.RecordSource) > Go tnTo > lnTo = sorter > Go tnFrom > lnFrom = sorter > If lnTo < lnFrom > Replace sorter With sorter+1 For Between(sorter,lnTo,lnFrom-1) > Else > Replace sorter With sorter-1 For Between(sorter,lnFrom+1,lnTo) > Endif > Go tnFrom > Replace sorter With lnTo > This.Refresh > Endproc >Enddefine > >Define Class mySorterGrid1 As myGrid > Name = "grdMyGrid" > > Procedure DragDrop > Lparameters oSource, nXCoord, nYCoord, nState > This.MyDragDrop(oSource, nXCoord, nYCoord, nState) > Endproc >Enddefine > >Define Class mySorterGrid2 As myGrid > Name = "grdMyGrid" > > Procedure DragOver > Lparameters oSource, nXCoord, nYCoord, nState > This.MyDragDrop(oSource, nXCoord, nYCoord, nState) > Endproc >Enddefine > >Define Class myColumn As Column > Resizable = .F. > Movable = .F. > Procedure Init > Lparameters cControlSource, nIndex > With This > .ControlSource = cControlSource > .ColumnOrder = nIndex > .AddObject("myText","myGridTxtBox") > .CurrentControl = "myText" > .Sparse = .F. > Endwith > Endproc >Enddefine > >Define Class myGridTxtBox As TextBox > Name = "Text1" > BorderStyle = 0 > > Procedure MouseDown > Lparameters nButton, nShift, nXCoord, nYCoord > If nButton=1 > nStart=Seconds() > Do While Mdown() And Seconds() - nStart < 1 > If Seconds() - nStart > 0.8 > This.Drag(1) > Exit > Endif > Enddo > Endif > Endproc >Enddefine >PS: Drag is designed to start if button is held down at least 0.8secs.