Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Listview.Items.Insert ? (https://www.delphipraxis.net/57970-listview-items-insert.html)

lucius 29. Nov 2005 15:02


Listview.Items.Insert ?
 
Hallo Leute,

Ich moechte meiner Listview von oben ab mit Neuen Eintragen fuellen.
Habe aber leider kein Plan wie ich das hinkriegen soll.
Habe schon etwas rumgeguckt hier im Forum aber irgendwie komm ich nicht weiter.
Delphi-Quellcode:
for o := 0 to w.Count -1 do
    begin
    listview.Items.BeginUpdate;
    x.Insert(0, w.Strings[o]);
    z := CreateStrings(SimpleRSS.Items.Items[o].Description);
      listitem := listview.Items.Insert[o]; <---------- Muesste richtig sein?
////////////////////Neu Eintraege///////////////////////////////
      listitem.Caption := IntToStr(Succ(o));
      z.Values['Added'] := Parse(' ', z.Values['Added'], 1);
      listitem.SubItems.Add(z.Values['Added']);
      listitem.SubItems.Add(z.Values['Category']);
      listitem.SubItems.Add(SimpleRSS.Items.Items[o].Title);
      listitem.SubItems.Add(z.Values['Size']);
      listitem.SubItems.Add(z.Values['Status']);
      listitem.SubItems.Add(z.Values['Speed']);
      listitem.SubItems.Add(SimpleRSS.Items.Items[o].Link);
      listitem.SubItems.Add(z.Values['Download']);
///////////////////////////////////////////////////////////////
      Neu.Caption := 'Anzahl NEUE Items: ' + IntTostr(w.count);
    z.Free;
    listview.Items.EndUpdate;
    end;
Kann mir da einer bitte weiterhelfen?
Besten Dank im voraus.

dahead 29. Nov 2005 15:06

Re: Listview.Items.Insert ?
 
Du musst Insert(0, ...) verwenden, da du die neuen Einträge ja immer ganz oben haben willst. Deine Loopvariable o erhöht sich ja mit jedem durchlauf.

Dein Label solltest du nach dem Durchlauf aktualisieren. Bei jedem Aufruf wäre sinnlos, es sein denn du willst, dass er hochzählt. Dann könntest du noch ein Application.ProcessMessages einbauen.

lucius 29. Nov 2005 15:11

Re: Listview.Items.Insert ?
 
Hi dahead und wie uebergebe ich dan
Delphi-Quellcode:
////////////////////Neu Eintraege///////////////////////////////
      listitem.Caption := IntToStr(Succ(o));
      z.Values['Added'] := Parse(' ', z.Values['Added'], 1);
      listitem.SubItems.Add(z.Values['Added']);
      listitem.SubItems.Add(z.Values['Category']);
      listitem.SubItems.Add(SimpleRSS.Items.Items[o].Title);
      listitem.SubItems.Add(z.Values['Size']);
      listitem.SubItems.Add(z.Values['Status']);
      listitem.SubItems.Add(z.Values['Speed']);
      listitem.SubItems.Add(SimpleRSS.Items.Items[o].Link);
      listitem.SubItems.Add(z.Values['Download']);
///////////////////////////////////////////////////////////////
an Insert(0,...)?
Etwa so?
Delphi-Quellcode:
listitem.SubItems.Insert(0, z.Values['Added']);
listitem.SubItems.Insert(0, z.Values['Category']);
listitem.SubItems.Insert(0, SimpleRSS.Items.Items[o].Title);
....
Das habe ich naemlich schon versucht und bekam nen Listindex out of bounds.

dahead 29. Nov 2005 15:16

Re: Listview.Items.Insert ?
 
nein, du machst das wie folgt:

Delphi-Quellcode:
var
 LI: TListItem;
begin
  LI := ListView1.Items.Insert(0);
  LI.Caption := 'Neuer Eintrag';
  LI.SubItems.Add('Spalte 1');
  LI.SubItems.Add('Spalte 2');
  ...
end;
mit LI gibst du der ListView ja den Listeneintrag. Diesen fügst du via Insert(0) nach ganz oben. Die restlichen Eigenschaften (also Texte der Spalten) weist du einfach mit SubItems.Add('Test') zu.

edit:

ich hab mir mal deinen o. g. quelltext angesehen. es müsste etwa (etwa, da ich nicht weiß, was die variable w ist) so aussehen:

Delphi-Quellcode:
var
  LI: TListItem;
  O: Integer;
begin

  ListView.Items.BeginUpdate; // wichtig: vor schleifendurchlauf, da sonst mit jedem neuen eintrag aufgerufen wird.

  for o := 0 to w.Count -1 do
   begin

    x.Insert(0, w.Strings[o]); //keine ahnung was x ist.

    z := CreateStrings(SimpleRSS.Items.Items[o].Description); //schätze hier liest du die strings aus

    listitem := listview.Items.Insert(0); //neuen listview eintrag ganz oben erstellen

    listitem.Caption := IntToStr(Succ(o)); // caption zuweisen

    z.Values['Added'] := Parse(' ', z.Values['Added'], 1); //auch keine ahnung

    // subitems erstellen
    listitem.SubItems.Add(z.Values['Added']);
    listitem.SubItems.Add(z.Values['Category']);
    listitem.SubItems.Add(SimpleRSS.Items.Items[o].Title);
    listitem.SubItems.Add(z.Values['Size']);
    listitem.SubItems.Add(z.Values['Status']);
    listitem.SubItems.Add(z.Values['Speed']);
    listitem.SubItems.Add(SimpleRSS.Items.Items[o].Link);
    listitem.SubItems.Add(z.Values['Download']);
   end;

  Neu.Caption := 'Anzahl NEUE Items: ' + IntTostr(w.count); // am ende der schleife, bzw. danach das label akt.
  z.Free; //keine anhnung, könnte auch noch am ende der schleife freigegeben werden, ich weiß nicht wann du das erstellst.
  listview.Items.EndUpdate; //und hier definitiv nach durchlauf der schleife das endupdate einläuten.

lucius 29. Nov 2005 15:25

Re: Listview.Items.Insert ?
 
Jetzt klappt es Vielen Dank dahead. :-D

dahead 29. Nov 2005 15:27

Re: Listview.Items.Insert ?
 
bitte, kein problem.


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:03 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz