Autor Beitrag
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 10.03.06 13:08 
Mahlzeit,

ich möchte bei einer Combobox Items hinzufügen, diese müssen hinterher aber mit einem Wert in Verbindung gebracht werden. Dafür bietet TStrings ja ValueFromIndex[x]:String; das klappt soweit auch.
Das Problem ist, dass dieser gesamte Ausdruck auch angezeigt wird und nicht nur der Name der Auswahl.

Was mache ich da bloß falsch :(
giantdwarf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5, Delphi 2006 Prof, Delphi 2009
BeitragVerfasst: Fr 10.03.06 14:25 
Hallo,

wenn ich es richtig verstehe soll der Wert auch mit angezeigt werden. Wenn Du irgendetwas mit den Items in Verbindung bringen willst, was unsichtbar bleiben soll, nutze doch
Combobox1.Items.AddObject( 'Item1', oObj );
Wobei oObj irgendein Objekt abgeleitet von TObject ist. Da kann man mit einen entsprechenden Definition eigentlich alles reinpacken.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 10.03.06 14:27 
Und hier gibt es ein Beispiel: www.michael-puff.de/...es/LB_AddObject.html
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: So 12.03.06 08:04 
Danke, aber das kenne ich natürlich schon ;)

Ich habe das Problem, das es sich dabei wirklich nur um einen Wert handelt. Da kam mir die Idee mit den Values. Irgendwie muss das doch gehen, das dort nur der Name Teil des Strings angezeigt wird. Vorher hatte ich eine Lösung indem ich ein Array hatte und mit einer TComboboxex.ItemsEx.Data auf den entsprechenden Wert gepointert habe.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 12.03.06 09:55 
Hallo,

dann sorg doch in OnDrawItem dafür das nur der Name als Text ausgegeben wird. :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: So 12.03.06 19:13 
Autsch :roll: wieder wieder mit Hammer und Meißel...

Ich dachte, das das nativ schon so drin wäre....na dann werde ich meine Zeigergeschichte wieder entkommentieren, obwohl das Jetzige so schön aussah :cry:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 13.03.06 00:12 
Hallo,
user profile icondigi_c hat folgendes geschrieben:
Autsch :roll: wieder wieder mit Hammer und Meißel...

hast Du Dir dabei auf den Daumen gehauen :bawling: , war aber so nicht gedacht. :mrgreen:
Brauchst doch nur zwei Zeilen Code im OnDrawItem dafür:
ausblenden Delphi-Quelltext
1:
2:
ComboBox1.Canvas.FillRect(Rect);
ComboBox1.Canvas.TextOut(Rect.Left+2,Rect.Top+2,ComboBox1.Items.Names[Index]);

user profile icondigi_c hat folgendes geschrieben:
Ich dachte, das das nativ schon so drin wäre....na dann werde ich meine Zeigergeschichte wieder entkommentieren, obwohl das Jetzige so schön aussah :cry:
meinst Du mit Zeigergeschichte das Array aus dem vorigen Post? Wenn man nur einen Wert an ein Item binden will braucht man kein Array:
ausblenden Delphi-Quelltext
1:
2:
3:
ComboBox1.Items.AddObject('blabla',Pointer(5));
//lesen
i := Integer(ComboBox1.Items.Objects[x]);

Dann noch zusätzlich das mit Hammer und Meißel, dann kann man auch zwei Werte einfach an ein Item binden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
ComboBox1.Items.AddObject('NameX=0815',Pointer(5));
//lesen
showmessage(ComboBox1.Items.Names[0]);
showmessage(ComboBox1.Items.Values[ComboBox1.Items.Names[0]]);
showmessage(IntToStr(Integer(ComboBox1.Items.Objects[0])));

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )