青
青云
Unregistered / Unconfirmed
GUEST, unregistred user!
如DataSet有10条记录;那么可以把第8条往上移1条;是它变成第7条;原来的第7条就变成第8条;感觉可以用 DataSet.Moveby(-1);但实际上该函数只是把光标网上移了一下;在DBGridEh的 OptionsEh 属性里有dghRecordMoving选项;当设置 DBGridEh.OptionsEh :=DBGridEh.OptionsEh +[dghRecordMoving];的时候,就可以在DBGridEh上移动记录间的次序;不过,我想放两个button ,分别对当前记录做上移下移处理;不知道如何通过代码实现,好像挺复杂,大概思路是借助TBookmark ;我把DbGridEh实现该功能的代码挖出来,如下:不知道如何做成上移下移的函数。function TCustomDBGridEh.CheckBeginRowMoving(MouseX, MouseY: Integer; CheckInOnly: Boolean): Boolean;var Cell: TGridCoord; ARect: TRect; Bookmark: TBookmarkStr; DataRow: Integer;// TreeLevel: Integer; DrawInfo: TGridDrawInfoEh;begin Result := False; if not DataLink.Active or not (dghRecordMoving in OptionsEh) then Exit; Cell := MouseCoord(MouseX, MouseY); Result := (Cell.X >= 0) and (Cell.X < FIndicatorOffset) and (Cell.Y > TopDataOffset - 1) and FDataLink.Active and not (DataSource.Dataset.EOF and DataSource.Dataset.BOF); if Result then begin DataRow := Cell.Y - TopDataOffset; InstantReadRecordEnter(DataRow); try Bookmark := FDataLink.Dataset.Bookmark; FMoveRowSourLevel := -1; if MemTableSupport then FMoveRowSourLevel := FIntMemTable.GetTreeNodeLevel; if CanSelectType(gstRecordBookmarks) then Result := FBookmarks.CurrentRowSelected and (GetShiftState * [ssShift, ssAlt, ssCtrl] = []); finally InstantReadRecordLeave; end; if not Result then Exit; ARect := CellRect(Cell.X, Cell.Y); Result := TRUE; if CheckInOnly then Exit; FMoveRowSour := DataRow + TopDataOffset; FMoveRowDest := FMoveRowSour; FMoveBookmarkSour := Bookmark; if BeginDataRowDrag(FMoveRowSour, FMoveRowDest, Point(MouseX, MouseY)) then begin FDBGridEhState := dgsRowMoving; Update; CalcDrawInfo(DrawInfo); FMoveRowLeftBounds := CalcLeftMoveLine(Cell.Y, Point(MouseX, MouseY), FMoveRowDestLevel); DrawDataRowMove(FMoveRowLeftBounds, ClientWidth);// MoveDrawn := True; SetTimer(Handle, 1, 60, nil); FTracking := TRUE; end; end;end;