Delphi-PRAXiS
Seite 1 von 2  1 2      

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/)
-   -   Listbox1.items.delete[1] Problem (https://www.delphipraxis.net/96587-listbox1-items-delete%5B1%5D-problem.html)

trolojik2 27. Jul 2007 00:11


Listbox1.items.delete[1] Problem
 
Hi

Listbox1 contains about 1000 lines. it get news from a web site and automaticly delete old news
in this way listbox1.delete.items[1];

But when i scrolled listbox1 and when deleted an item scrolls going start it seems like listbox1.itemindex:=0;

I dont want to go back ,i want when deleted an item scroll pos doesnt change.
Is it possible ?

Die Muhkuh 27. Jul 2007 00:16

Re: Variable global in einer Pas Datei
 
Hi trolojik2,
at first: Welcome to the Delphi-PRAXiS :dp:

I think, the ListBox isn't a good component to keep about 1000 items. Maybe you should take a look to Mike Lischke's VirtualStringTree.

I think you have a button to delele the news? So you should keep the delete pos into a variable and scroll to it, after you deleted the old news, just like that:

Delphi-Quellcode:
procedure TForm1.DeleteNews(Sender: TObject);
var
  I: Integer;
begin
  I := ListBox1.ItemIndex; // The "old newspos"
  ListBox1.Delete(I);
  ListBox1.ItemIndex := I;
end;
Regards,

Manuel :hi:

trolojik2 27. Jul 2007 00:19

Re: Listbox1.items.delete[1] Problem
 
but i will not click an item.
it deletes automaticly i only click listboxs scroll

Thanks for your relation

Regards

Die Muhkuh 27. Jul 2007 00:22

Re: Listbox1.items.delete[1] Problem
 
Hi,

could you show your procedure to delete and old news?

Regards

trolojik2 27. Jul 2007 00:26

Re: Listbox1.items.delete[1] Problem
 
at first my project is client chat project.

listbox1 contains nick names
on a user connect server listbox1 add nick on lines with listbox1.items.add(nick);
when a user disconnected or quited item deletes automaticly in this way > listbox1.items.delete(listbox1.items.indexof(nick) );

i will not click any nick (item)
when im looking nick list with listbox's scroll it this time if a user quits or disconnected
scroll going start of listbox1
I dont want to change scroll pos when a user quited

Die Muhkuh 27. Jul 2007 00:47

Re: Listbox1.items.delete[1] Problem
 
Hi,

i tried this here:

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ListBox1.ItemIndex := ListBox1.TopIndex; // marked
  ListBox1.Selected[ListBox1.TopIndex] := false; // marked

  ListBox1.Items.Delete(Random(ListBox1.Items.Count)); // just for test
end;
I think it works well. Maybe you should try the marked lines of code

[edit]OK, sometimes it doens't work perfect, but it'll be a good start for the perfect code ;) [/edit]

trolojik2 27. Jul 2007 00:55

Re: Listbox1.items.delete[1] Problem
 
woaw it works you are number one :)
Sorry about my english

I putted form a scrollbar, listbox's fake scrollbar :)

Delphi-Quellcode:
procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
listbox1.ItemIndex:=scrollbar1.Position;
end;

and when deleted

Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
 i:integer;
begin
  I := ListBox1.ItemIndex; // The "old newspos"
  ListBox1.items.Delete(1);
  ListBox1.ItemIndex := I;
  scrollbar1.Max:=listbox1.Items.Count-1;

end;
it works too but fake way

thanks for your help.

Regards

trolojik2 27. Jul 2007 00:57

Re: Listbox1.items.delete[1] Problem
 
in your opinion which way i should use ?

Regards

Die Muhkuh 27. Jul 2007 00:59

Re: Listbox1.items.delete[1] Problem
 
Hi,

no problem. This board is to help people with problems ;)

Which way? I think you should use the way you like. In my example you don't have a blue rect about the last item (ListBox1.Select[...]...). But both your and my codes work well, so you can decide, what you want to have.

trolojik2 27. Jul 2007 01:02

Re: Listbox1.items.delete[1] Problem
 
Thanks again
Now i have to decide :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:53 Uhr.
Seite 1 von 2  1 2      

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