was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

35 Visitors Online


 
...Items im TListView austauschen?
Autor: Mike Shkolnik
Homepage: http://www.scalabium.com
[ Tip ausdrucken ]  

Tip Bewertung (6):  
     


Today I want to describe how you may exchange some items in standard TListView.
For example, you have 5 items and want to swap
positions for first and third items

Problem that standard TListView component haven't
such method and you must realize it yourself.

We remember that the standard way from old Pascal times
(for numbers) is:

procedure Swap(X, Y: Integer);
var
  
s: Integer;
begin
  
s := X;
  X := Y;
  Y := X
end;



Something similar we can do with TListItem too.
But just to save all strings (caption+sub items) somewhere is not enough because TListItem class have a lot of other information (image indexes, pointer as Data, etc)

So correct way is to use Assign method:

procedure ExchangeItems(lv: TListView; const i, j: Integer);
var
  
tempLI: TListItem;
begin
  
lv.Items.BeginUpdate;
  try
    
tempLI := TListItem.Create(lv.Items);
    tempLI.Assign(lv.Items.Item[i]);
    lv.Items.Item[i].Assign(lv.Items.Item[j]);
    lv.Items.Item[j].Assign(tempLI);
    tempLI.Free;
  finally
    
lv.Items.EndUpdate
  end;
end;



So structure is a same as in our sample for Integer. All what we added are
BeginUpdate and EndUpdate (just allow to reduce a flickering)

So if you want to exchange items in any ListView, just call this procedure...

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners