Autor Beitrag
Gosa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Mi 05.01.05 18:26 
Hallo,

Ich habe eine ListBox die ich manchmal updaten muss (Ich loesche sie komplett und schreibe sie wieder voll). Wenn ich das mache dann springt die aber immer wieder auf position 0 zurück. Gibt es eine möglichkeit die Posiotion vor dem Update zu bekommen so das ich die Scroolbar nachdem Update wieder auf den alten Wert setzen kann?
mad_progger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 49

WIN XP, Linux
D7 Pro
BeitragVerfasst: Mi 05.01.05 19:22 
Falls du man in der Listbox nur einen Eintrag markieren darf und dieser danach die selbe Position hat:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var i,p:integer;
    gefunden:boolean;
begin
i:=0
while not gefunden AND (i<listbox.count) do begin
if listbox.selected[i] 
  then begin
  p:=i;
  gefunden:=true;
  end
  else INC(i)
end;
//deine AKtualisierungen
listbox.selected[p]:=true;
end;


edit: Hab gerade kein Delphi zur hand und kann deswegen nicht sagen ob es so funktioniert. Zumindest hast du so aber denselben Eintrag wieder markiert!


Zuletzt bearbeitet von mad_progger am Mi 05.01.05 19:28, insgesamt 1-mal bearbeitet
teebee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 109


D6 Prof
BeitragVerfasst: Mi 05.01.05 19:24 
Du könntest Dir vor dem Update den TopIndex der ListBox merken und hinterher wieder setzen.
Ansonsten gibt es auch noch GetScrollInfo/SetScrollInfo.

Gruß, teebee
MrSaint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1033
Erhaltene Danke: 1

WinXP Pro SP2
Delphi 6 Prof.
BeitragVerfasst: Mi 05.01.05 19:28 
mad_progger hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var i,p:integer;
    gefunden:boolean;
begin
i:=0
while not gefunden AND (i<listbox.count) do begin
if listbox.selected[i] 
  then begin
  p:=i;
  gefunden:=true;
  end
  else INC(i)
end;
//deine AKtualisierungen
listbox.selected[p]:=true;
end;


schneller:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var iPosition: integer;

begin
  iPosition := ListBox1.ItemIndex;
  
  //deine Aktualisierungen

  ListBox1.Selected[iPosition] := true;
end;


:D

MrSaint

_________________
"people knew how to write small, efficient programs [...], a skill that has subsequently been lost"
Andrew S. Tanenbaum - Modern Operating Systems
mad_progger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 49

WIN XP, Linux
D7 Pro
BeitragVerfasst: Mi 05.01.05 19:31 
MrSaint hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var iPosition: integer;

begin
  iPosition := ListBox1.ItemIndex;
  
  //deine Aktualisierungen

  ListBox1.Selected[iPosition] := true;
end;


:D

MrSaint


Hatte gerad kein Delphi zur Hand und wußte nicht, ob Listbox einen Itemindex hab. Verwend das meist mit multiselect und da muss er es so machen, bloß eben mit p als dynamischen cardinal-array und ohne das gefunden (halt while (i<listbox.count) and (length(p)<listbox.selcount)
Gosa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Do 06.01.05 11:00 
Vielen dank!

War ja eigentlich ganz einfach... :) (Nur war ich etwas blöd)