Listview中行之间的上下移动

来源:互联网 发布:办公软件培训心得体会 编辑:程序博客网 时间:2024/05/21 07:01
  1. procedure TForm1.N5Click(Sender: TObject);
  2.   var
  3.       idex:   Integer;
  4.       TmpList1,   TmpList2,   TmpupList:   TListItem;
  5.   begin   
  6.       TmpList1   :=   lv2.Selected;
  7.       if   TmpList1   =   nil   then   Exit;   
  8.       idex   :=   TmpList1.Index;   
  9.       if   idex   =   0   then   Exit;
  10.       TmpList2   :=   lv2.Items[idex   -   1];
  11.       lv2.Items.BeginUpdate;   
  12.       try   
  13.           TmpupList   :=   lv2.Items.Add;
  14.           TmpupList.Assign(TmpList1);
  15.           TmpList1.Assign(TmpList2);
  16.           TmpList2.Assign(TmpupList);
  17.           TmpList2.Selected   :=   True;
  18.           lv2.SetFocus;
  19.       finally
  20.           TmpupList.Delete;
  21.           lv2.Items.EndUpdate;
  22.       end;       
  23.   end;
  24. procedure TForm1.N6Click(Sender: TObject);
  25.   var
  26.       idex,   iCount:   Integer;   
  27.       TmpList1,   TmpList2,   TmpdwList:   TListItem;   
  28.   begin
  29.       TmpList1   :=   lv2.Selected;
  30.       if   TmpList1   =   nil   then   Exit;
  31.       idex   :=   TmpList1.Index;   
  32.       iCount   :=   lv2.Items.Count   -   1;
  33.       if   idex   =   iCount   then   Exit;   
  34.       TmpList2   :=   lv2.Items[idex   +   1];
  35.       lv2.Items.BeginUpdate;
  36.       try   
  37.           TmpdwList   :=   lv2.Items.Add;
  38.           TmpdwList.Assign(TmpList1);
  39.           TmpList1.Assign(TmpList2);
  40.           TmpList2.Assign(TmpdwList);
  41.           TmpList2.Selected   :=   True;
  42.           lv2.SetFocus;
  43.       finally
  44.           TmpdwList.Delete;
  45.           lv2.Items.EndUpdate;
  46.       end;
  47.   end;
原创粉丝点击