Autor Beitrag
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 08:38 
Hallo,

Ich habe eine ListBox^^ und da stehen werte drin, logisch. Z.B:

    Wert1
    Wert2
    Wert3
    Wert4
    Wert5

Ich möchte jetzt (OHNE anklicken) mit einem Befehl (der z.B. durch einen Button ausgelöst wird) das ein Eintrag mit dem Inhalt "Wert2" gelöscht wird. Wenn man es so hat wie in meinem Beispiel, könnte man das einfach mit
ausblenden Delphi-Quelltext
1:
ListBox.Items.Delete (1);					

machen. Aber was ist wenn man die Nummer (glaube das heißt Index) nicht kennt?
Also müsste warscheinlich der Wert (automatisch) rausgefunden werden und dann der Befehl zum Löschen gegeben werden.
Aber wie?


Zuletzt bearbeitet von DarkLord05 am So 29.05.05 11:34, insgesamt 1-mal bearbeitet
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 29.05.05 08:50 
hi,
schau dir mal IndexOf an

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
DarkLord05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 08:56 
Irgendwie klappt das nicht ganz :-(
Mach mit der ListBox jetzt das 1. mal was^^

Habe
ausblenden Delphi-Quelltext
1:
ListBox.Items.IndexOf ('Wert2');					

eingegeben.
Resultat: ...is not a valid Integer Value.

Aber da stand das man ein String eingeben muss... oder habe ich das falsch interpretiert?
Was muss ich denn genau machen... kannste mal einen Codeschnipsel machen?
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 29.05.05 10:16 
meines Erachtens so:ListBox.Items.Delete(ListBox.Items.IndexOf('Wert')) (kann's jetzt aber nicht testen)
mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 29.05.05 10:25 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  Index: Integer;
begin

  Index := ListBox1.Items.IndexOf('Wert2');
  if Index > -1 then
    ListBox1.Items.Delete(Index);

end;

_________________
Ciao, Sprint.
DarkLord05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 10:54 
Viele Danke.
Beide Varianten funktionieren.
DarkLord05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 11:36 
Habe wohl zu früh geklickt^^ (oder soll ich ein neues Topic öffnen?)

In der Liste stehen z.B. 3 Werte


    Wert1
    Wert2
    Wert3


Wenn ich Wert2 lösche sieht die Liste so aus:


    Wert1
    Wert3
    Wert1


Was ist da los?
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: So 29.05.05 11:50 
:? Kann eigentlich net sein. Hast du irgendwas in deinem Code überseh'n?
DarkLord05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 11:52 
Also das gehört zu meinem Chat-Programm.
Wenn sich einer einloggt wird sein Name in die Liste "geaddet". Und wenn der sich halt ausloggt wird das mit einem der obrigen codes gelöscht.
Ich versteh es ja selber nicht, dachte erst das wäre eine Eisntellung der ListBox.
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 29.05.05 11:58 
zeig mal code, denn mit raten ist das jetzt schwer rauszufinden.
zeichnest du die Liste selber (ownerdraw)? wenn ja musst du sie nach dem Löschen neuzeichnen.(Listbox.Repaint)

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
DarkLord05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 12:06 
Die ListBox ist da (auf ne anderen Form).
Wenn der Server aufgemacht wird wird folgendes gemacht:
ausblenden Delphi-Quelltext
1:
MembersForm.ListBox.Items.Add (NickName.Text); // NickName ist die EditBox wo der Name drin ist					


Wenn einer nun Connected, dann wird folgendes ausgeführt:

ausblenden Delphi-Quelltext
1:
MembersForm.ListBox.Items.Add (LoginName); // LoginName ist ne String Variable					

Wenn einer Disconnected passiert das:

ausblenden Delphi-Quelltext
1:
MembersForm.ListBox.Items.Delete (ListBox.Items.IndexOf(LoginName));					
StefanH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1144

Win XP
D5 Standard, D7 Pers, D2005 Pers
BeitragVerfasst: So 29.05.05 13:17 
user profile iconDarkLord05 hat folgendes geschrieben:
Wenn einer Disconnected passiert das:

ausblenden Delphi-Quelltext
1:
MembersForm.ListBox.Items.Delete (ListBox.Items.IndexOf(LoginName));					



ausblenden Delphi-Quelltext
1:
MembersForm.ListBox.Items.Delete (MembersForm.ListBox.Items.IndexOf(LoginName));					


du solltest das Item noch in der gleichen Listbox suchen, aus der du es löschen willst ;)
(das fällt mir auf... sonst nichts)

_________________
"Als es noch keine Computer gab, war das Programmieren noch relativ einfach."(Edsger W. Dijkstra)
"Ich bin nicht von Sinnen, sondern ich rede wahre und vernünftige Worte." (Paulus)
DarkLord05 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: So 29.05.05 14:17 
Wie dumm kann ein einzelner Mensch sein.....
Ich habe beim Server im ONDisconnect befehl reingeschrieben das der Nickname in die Liste kopiert wird......so kam es zu dem 1. Eintrag (der der Derver ist) der doppelt ist....

Danke trotzdem für die mühe.... nächstes mal gucke ich lieber vorher nochmal nach.... :oops: :oops:


bitte CLOSE