打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
移动任意行的功能
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.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
CxGrid选中单行FocusedRowIndex与FocusedRecordIndex区别
Delphi读取excel数据
Cxgrid获取选中行列,排序规则
Java 使用 iText动态生成PDF文档
使用TOsVersion类
TStringList.VALUES 表示什么?怎么用?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服