Autor Beitrag
Jacer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 105

Windows 7, Vista, Ubuntu
HTML,CSS,PHP,Delphi 7
BeitragVerfasst: Sa 17.02.07 16:07 
Also ich habe (wie ihr vielleicht schon hier mitbekommen habt :D) ein kleines Mitarbeiter-Verwaltungsprogramm geschrieben.
Dabei existiert ein Hauptfenster mit einer ListBox und zwei weitere Formulare für das Editieren und das Anlegen eines neuen Mitarbeiters.

Wenn ich jetzt beispielsweise dass Formular Editieren aufrufe, und auf Bestätigen gehe, aktualisiere ich die ListBox mit folgenden Zeilen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
    while not FrmMitarbeiter.TblMitarbeiter.eof do
      begin
        FrmMitarbeiter.ListBoxMitarbeiter.Items.Add(FrmMitarbeiter.TblMitarbeiter.FieldbyName('Nachname').Asstring + ', ' + FrmMitarbeiter.TblMitarbeiter.fieldbyname('Vorname').Asstring);
        FrmMitarbeiter.TblMitarbeiter.Next;
      end;


Mein Problem ist, dass dabei die ListBox ihre Selektion von vor dem Aufruf des zweiten Formulars verliert.
Kann man die Selektion bzw den ItemIndex einer ListBox irgendwie zwischenspeichern um ihn nach der Aktualisierung wieder zu aktivieren?

_________________
A look in the eyes often says more than a hundred words could ever express.
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Sa 17.02.07 16:10 
ja, kann man, über den ItemIndex.

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 17.02.07 16:11 
Moin!

Die VCL-Kompo TLisBox kann das nicht von Hause aus; mußt du schon selbst machen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jacer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 105

Windows 7, Vista, Ubuntu
HTML,CSS,PHP,Delphi 7
BeitragVerfasst: Sa 17.02.07 16:14 
user profile iconHelgeLange hat folgendes geschrieben:
ja, kann man, über den ItemIndex.


Tut mir Leid aber die Antwort ist so präzise dass ich sie nicht mehr verstehe!

user profile iconNarses hat folgendes geschrieben:
Moin!

Die VCL-Kompo TLisBox kann das nicht von Hause aus; mußt du schon selbst machen. ;)

cu
Narses


Könntest du mir einen Denkanstoss geben? :)

_________________
A look in the eyes often says more than a hundred words could ever express.
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Sa 17.02.07 16:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
OldIdx := ListView.ItemIndex
...
...
...
ListView.ItemIndex := OldIdx;

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 17.02.07 16:15 
Moin!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  Temp: Integer;

begin
  Temp := ListBox1.ItemIndex;
  // Dinge tun...
  ListBox1.ItemIndex := Temp;

:rofl:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 17.02.07 16:16 
Aber prüfe, ob ListBox.ItemIndex > -1, sonst kommt es eventuell zu Zugriffsverletzungen!

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
HelgeLange
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 735
Erhaltene Danke: 6

Windows 7
Delphi7 - Delphi XE
BeitragVerfasst: Sa 17.02.07 16:18 
Kann man ItemIndex := -1 nicht setzen als "nein-ich habe nichts selektiert" ? *Helge sich da grad nicht sicher ist*

_________________
"Ich bin bekannt für meine Ironie. Aber auf den Gedanken, im Hafen von New York eine Freiheitsstatue zu errichten, wäre selbst ich nicht gekommen." - George Bernhard Shaw
Jacer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 105

Windows 7, Vista, Ubuntu
HTML,CSS,PHP,Delphi 7
BeitragVerfasst: Sa 17.02.07 16:18 
Gut dann war nu meine Formulierungen des Befehles falsch.
Ich dachte man müsste es wieder so machen:

ausblenden Delphi-Quelltext
1:
variable:= ListBox1.Items[ListBox.ItemIndex];					


Vielen Dank für die Hilfe!

_________________
A look in the eyes often says more than a hundred words could ever express.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 17.02.07 16:19 
Moin!

user profile iconGTA-Place hat folgendes geschrieben:
Aber prüfe, ob ListBox.ItemIndex > -1, sonst kommt es eventuell zu Zugriffsverletzungen!

Nein, tut es nicht; -1 hebt die Selektion einfach auf. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 17.02.07 16:20 
Nicht wenn du ListView.Items[Temp].Selected := True benutzt oder auf das Item zugreifen willst :roll:.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Jacer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 105

Windows 7, Vista, Ubuntu
HTML,CSS,PHP,Delphi 7
BeitragVerfasst: Sa 17.02.07 16:31 
So funktioniert jetzt alles. Hatte noch einen kleinen Fehler drinn!

Vielen Dank für die Hilfe ;)

_________________
A look in the eyes often says more than a hundred words could ever express.