Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change the position of a list item in a TListView (3) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
99
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a TListView object, and two buttons on a form. The ListView is populated 
with items all in one column, and I need to able to push one button to move the 
items up and the other button to move them down.

Answer:

Set ListView.HideSelection to false.
1   
2   procedure MoveItems(AListView: TListView; Up: Boolean = True);
3   var
4     OldItem, NewItem: TListItem;
5     AIndex: Integer;
6   begin
7     Assert(Assigned(AListView));
8     with AListView do
9     begin
10      Items.BeginUpdate;
11      try
12        OldItem := TListItem.Create(Items);
13        try
14          OldItem.Assign(Selected);
15          if Up then
16            AIndex := Selected.Index - 1
17          else
18            AIndex := Selected.Index + 1;
19          if not AIndex in [0..Items.Count - 1] then
20            Exit;
21          Selected.Delete;
22          NewItem := Items.Insert(AIndex);
23          NewItem.Assign(OldItem);
24          Selected := NewItem;
25        finally
26          OldItem.Free;
27        end;
28      finally
29        AListView.Checkboxes := False;
30        Items.EndUpdate;
31      end;
32    end;
33  end;
34  
35  procedure TForm1.Button1Click(Sender: TObject);
36  begin
37    MoveItems(ListView1, False);
38  end;
39  
40  procedure TForm1.Button2Click(Sender: TObject);
41  begin
42    MoveItems(ListView1);
43  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC