![]() |
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 ? |
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:
Regards,
procedure TForm1.DeleteNews(Sender: TObject);
var I: Integer; begin I := ListBox1.ItemIndex; // The "old newspos" ListBox1.Delete(I); ListBox1.ItemIndex := I; end; Manuel :hi: |
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 |
Re: Listbox1.items.delete[1] Problem
Hi,
could you show your procedure to delete and old news? Regards |
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 |
Re: Listbox1.items.delete[1] Problem
Hi,
i tried this here:
Delphi-Quellcode:
I think it works well. Maybe you should try the marked lines of code
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; [edit]OK, sometimes it doens't work perfect, but it'll be a good start for the perfect code ;) [/edit] |
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:
it works too but fake way
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; thanks for your help. Regards |
Re: Listbox1.items.delete[1] Problem
in your opinion which way i should use ?
Regards |
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. |
Re: Listbox1.items.delete[1] Problem
Thanks again
Now i have to decide :) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:53 Uhr. |
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