如何让DataSet的记录之间可以上下移动改变次(20)

  • 主题发起人 主题发起人 青云
  • 开始时间 开始时间

青云

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;
 
http://bbs.2ccc.com/topic.asp?topicid=327415
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
687
import
I
后退
顶部