5,388
社区成员
发帖
与我相关
我的任务
分享
procedure RowMoveTo(ACurIndex, AOrdIndex: Integer;
ATV: TcxGridDBTableView; AKeyColumn, AOrderColumn: TcxGridDBColumn);
var
i, j, ARecordIndex, AStopIndex: Integer;
ArrID: Array of string;
bm: TBookmark;
AKeyName, AOrderName: string;
// P: TFocusedRecordChanged;
begin
if ACurIndex = AOrdIndex then exit;
P := ATV.onFocusedRecordChanged;
ATV.onFocusedRecordChanged := nil;
with ATV.DataController do
begin
SetLength(ArrID, RecordCount);
ARecordIndex := GetRowInfo(ACurIndex).RecordIndex;
ArrID[AOrdIndex] := Values[ARecordIndex, AKeyColumn.Index];
if ACurIndex > AOrdIndex then
begin
i := 0;
j := i;
AStopIndex := RecordCount - 1;
if ACurIndex = AStopIndex then AStopIndex := ACurIndex - 1;
while i <= AStopIndex do
begin
if i = AOrdIndex then Inc(j);
if i = ACurIndex then Inc(i);
ARecordIndex := GetRowInfo(i).RecordIndex;
ArrID[j] := Values[ARecordIndex, AKeyColumn.Index];
Inc(i);
Inc(j);
end
end else
begin
i := RecordCount - 1;
j := i;
AStopIndex := 0;
if ACurIndex = 0 then AStopIndex := 1;
while i >= AStopIndex do
begin
if i = AOrdIndex then Dec(j);
if i = ACurIndex then Dec(i);
ARecordIndex := GetRowInfo(i).RecordIndex;
ArrID[j] := Values[ARecordIndex, AKeyColumn.Index];
Dec(i);
Dec(j);
end
end;
end;
with ATV.DataController.DataSet do
begin
AKeyName := AKeyColumn.DataBinding.FieldName;
AOrderName := AOrderColumn.DataBinding.FieldName;
bm := GetBookmark;
try
DisableControls;
if ACurIndex > AOrdIndex then
begin
for i := ACurIndex downto AOrdIndex do
if Locate(AKeyName, ArrID[i], []) then
begin
Edit;
FieldByName(AOrderName).AsInteger := i + 1;
Post;
end;
end else
begin
for i := ACurIndex to AOrdIndex do
if Locate(AKeyName, ArrID[i], []) then
begin
Edit;
FieldByName(AOrderName).AsInteger := i + 1;
Post;
end;
end;
finally
GotoBookmark(bm);
FreeBookmark(bm);
EnableControls;
end;
end;
SetLength(ArrID, 0);
// gdTvPositioning(ATV, AOrdIndex);
// ATV.onFocusedRecordChanged := P;
end;