Listview move up and move down

Source: Internet
Author: User
  Problematic
// Move the project selected by ListBox to 1st bitsListbox1.items. Move (listbox1.itemindex, 0 );// Move the selected project in listview to 1st bits procedure TForm1.Button5Click(Sender: TObject);
var
    sel:String;
begin
    with ListView1 do
    begin
        sel:=Selected.Caption;
        Items.Insert(0).caption:=sel;
        DeleteSelected;
        SetFocus;
        Items[0].Selected:=True;
    end;
end;
  // Move the selected project in Treeview to 1st bits 
// Move the listview up and down procedure ListViewItemMoveUpDown(lv: TListView; Item: TListItem; MoveUp, SetFocus: Boolean);
var
  DestItem: TListItem;
begin
  if (Item = nil) or
    ((Item.Index - 1 < 0) and MoveUp) or
    ((Item.Index + 1 >= lv.Items.Count) and (not MoveUp))
    then Exit;
  lv.Items.BeginUpdate;
  try
    if MoveUp then
      DestItem := lv.Items.Insert(Item.Index - 1)
    else
      DestItem := lv.Items.Insert(Item.Index + 2);
    DestItem.Assign(Item);
    lv.Selected := DestItem;
    Item.Free;
  finally
    lv.Items.EndUpdate;
  end;
  if SetFocus then lv.SetFocus;
  DestItem.MakeVisible(False);
end;
 
procedure TForm1.Button3Click(Sender: TObject);
begin
   ListViewItemMoveUpDown(ListView1, ListView1.Selected, True, True);//é?ò?
end;
 
procedure TForm1.Button4Click(Sender: TObject);
begin
   ListViewItemMoveUpDown(ListView1, ListView1.Selected, False, True);//??ò?
end;


From Weizhi note (wiz)

Attachment List

     

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.