uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, cxPlatformTypes,
Dialogs, cxRuntimeCore, cxModuleBaseFrm,cxGrid,cxGridDBTableView,db,cxrecordset,cxDialogs;
var AGrid:TcxGrid;
AcxGridTableView:tcxGridDBTableView;
copypaste,title: Variant;
ColCount,i,j,ItemNo,LRealIndex:integer;
isup,islast,isfirst:boolean;
atable:tcxrecordsettableitem;
cptable: TcxFieldGroupItem;
bookmark:tbookmark;
ys:string;
begin
if not IDialogs.showinput(iekedit,'请选择要移动的行数','','',false,ys) then exit;
try
LRealIndex:=strtoint(ys);
isup:=false;
islast:=false;
isfirst:=false;
AGrid:=TcxGrid(self.Editor.ContainerByName('产品资料').Control.Controls[1]);
atable:=self.Recordset.TableByName('产品资料');
cptable:=Self.Editor.ContainerByName('产品资料').FieldGroup;
AcxGridTableView:= TcxGridDBTableView(AGrid.ActiveView);
//LockWindowUpdate(AGrid.Handle);
//showmessage(inttostr(AcxGridTableView.DataController.Controller.SelectedRecords[0].Index));
i:=AcxGridTableView.DataController.Controller.SelectedRecords[0].Index;
if i= LRealIndex-1 then
begin
showmessage('当前行与移动行相同,不能执行');
exit;
end;
if LRealIndex-1<0 then
begin
showmessage('移动行数不能输小于1');
exit;
end;
if LRealIndex>AcxGridTableView.DataController.RowCount then
begin
showmessage('移动行数不能输超过'+inttostr(AcxGridTableView.DataController.RowCount));
exit;
end;
ColCount:=cptable.Fields.Count;
copypaste := vararraycreate([0,ColCount - 1], varVariant);
for j:= 0 to ColCount - 1 do
begin
if atable.FieldByName(cptable.fields.Items[j].name).AsString<>'' then
begin
copypaste[j] := atable.FieldByName(cptable.fields.Items[j].name).Value;// AcxGridTableView.DataController.Values[i,j];
end;
end;
//LRealIndex:=5;
LRealIndex:=LRealIndex-1;
if LRealIndex>=AcxGridTableView.DataController.RowCount-1 then
islast:=true
else if LRealIndex<0 then
begin
LRealIndex:=0;
isfirst:=true;
end
else isup:=true;
AcxGridTableView.Controller.DeleteSelection;
if isup or isfirst then
begin
IDialogs.ShowProgress('畅想软件','数据正在插入第'+inttostr(LRealIndex+1)+'行...');
AcxGridTableView.DataController.FocusedRecordIndex:=LRealIndex;
atable.Insert(idUp);
ItemNo:=AcxGridTableView.DataController.Controller.SelectedRecords[0].Index;
//ItemNo := AcxGridTableView.DataController.InsertRecord(LRealIndex);
end
else
begin
IDialogs.ShowProgress('畅想软件','数据正在追加到结尾...');
atable.Append;
ItemNo:=AcxGridTableView.DataController.Controller.SelectedRecords[0].Index;
end;
for j := 0 to ColCount - 1 do
begin
if copypaste[j]<>null then
begin
atable.FieldByName(cptable.fields.Items[j].name).value:=copypaste[j];
end;
end;
atable.post;
IDialogs.CloseProgress;
except
showmessage('行数必须为数字');
exit;
end;
end.