AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Listbox1.items.delete[1] Problem

Ein Thema von trolojik2 · begonnen am 27. Jul 2007 · letzter Beitrag vom 27. Jul 2007
Antwort Antwort
Seite 1 von 2  1 2      
trolojik2

Registriert seit: 27. Jul 2007
14 Beiträge
 
#1

Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:11
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 ?
  Mit Zitat antworten Zitat
Benutzerbild von Die Muhkuh
Die Muhkuh

Registriert seit: 21. Aug 2003
7.332 Beiträge
 
Delphi 2009 Professional
 
#2

Re: Variable global in einer Pas Datei

  Alt 27. Jul 2007, 00:16
Hi trolojik2,
at first: Welcome to the Delphi-PRAXiS

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
  Mit Zitat antworten Zitat
trolojik2

Registriert seit: 27. Jul 2007
14 Beiträge
 
#3

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:19
but i will not click an item.
it deletes automaticly i only click listboxs scroll

Thanks for your relation

Regards
  Mit Zitat antworten Zitat
Benutzerbild von Die Muhkuh
Die Muhkuh

Registriert seit: 21. Aug 2003
7.332 Beiträge
 
Delphi 2009 Professional
 
#4

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:22
Hi,

could you show your procedure to delete and old news?

Regards
  Mit Zitat antworten Zitat
trolojik2

Registriert seit: 27. Jul 2007
14 Beiträge
 
#5

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:26
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
  Mit Zitat antworten Zitat
Benutzerbild von Die Muhkuh
Die Muhkuh

Registriert seit: 21. Aug 2003
7.332 Beiträge
 
Delphi 2009 Professional
 
#6

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:47
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]
  Mit Zitat antworten Zitat
trolojik2

Registriert seit: 27. Jul 2007
14 Beiträge
 
#7

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:55
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
  Mit Zitat antworten Zitat
trolojik2

Registriert seit: 27. Jul 2007
14 Beiträge
 
#8

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:57
in your opinion which way i should use ?

Regards
  Mit Zitat antworten Zitat
Benutzerbild von Die Muhkuh
Die Muhkuh

Registriert seit: 21. Aug 2003
7.332 Beiträge
 
Delphi 2009 Professional
 
#9

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 00:59
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.
  Mit Zitat antworten Zitat
trolojik2

Registriert seit: 27. Jul 2007
14 Beiträge
 
#10

Re: Listbox1.items.delete[1] Problem

  Alt 27. Jul 2007, 01:02
Thanks again
Now i have to decide
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:23 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