Board index » delphi » D6: Getting icons into TComboBoxEx

D6: Getting icons into TComboBoxEx

Another dumb newbie question:

   (* cbxLocation is of type TComboBoxEx. *)
   (* This is actually set in the Object Inspector *)
   cbxLocation.ImageList := ImageList1;  // images for combo box

And, I have icons loaded into ImageList1.
Problem is ... when I do this:

var
   icon : TIcon;
   S : string;
begin
   icon := TIcon.Create;
   S := 'This is a menu item';
   ImageList1.GetIcon(1, icon);
   cbxLocation.Items.AddObject(S, icon);
end;

the icon doesn't get added, but the string S does. What am I doing wrong? How
do I get both the string and the icon in cbxLocation? As a side note, the
ImageList has a combination of 16x16 and 32x32 icons, some of them designed
using the Image Editor.

PJK

 

Re:D6: Getting icons into TComboBoxEx


I think this is in the wrong group, but you need to be accessing the ItemsEx
property of the combobox to change the image etc.  AddObject is the call
from TStrings which merely assigns something to an item in the abstract
list.

HTH

Nick

Quote
<xogb...@hotmail.com> wrote in message

news:6p7g8ugneetb67vao69i42calt48d4s6ga@4ax.com...
Quote
> Another dumb newbie question:

>    (* cbxLocation is of type TComboBoxEx. *)
>    (* This is actually set in the Object Inspector *)
>    cbxLocation.ImageList := ImageList1;  // images for combo box

> And, I have icons loaded into ImageList1.
> Problem is ... when I do this:

> var
>    icon : TIcon;
>    S : string;
> begin
>    icon := TIcon.Create;
>    S := 'This is a menu item';
>    ImageList1.GetIcon(1, icon);
>    cbxLocation.Items.AddObject(S, icon);
> end;

> the icon doesn't get added, but the string S does. What am I doing wrong?
How
> do I get both the string and the icon in cbxLocation? As a side note, the
> ImageList has a combination of 16x16 and 32x32 icons, some of them
designed
> using the Image Editor.

> PJK

Re:D6: Getting icons into TComboBoxEx


Thanks. It finally worked.

PJK

On Sat, 9 Mar 2002 12:31:30 -0000, "Nicholas Robinson" <nr@nrobin_demon_co_uk>
wrote:

Quote
>I think this is in the wrong group, but you need to be accessing the ItemsEx
>property of the combobox to change the image etc.  AddObject is the call
>from TStrings which merely assigns something to an item in the abstract
>list.

>HTH

>Nick
><xogb...@hotmail.com> wrote in message
>news:6p7g8ugneetb67vao69i42calt48d4s6ga@4ax.com...
>> Another dumb newbie question:

>>    (* cbxLocation is of type TComboBoxEx. *)
>>    (* This is actually set in the Object Inspector *)
>>    cbxLocation.ImageList := ImageList1;  // images for combo box

>> And, I have icons loaded into ImageList1.
>> Problem is ... when I do this:

>> var
>>    icon : TIcon;
>>    S : string;
>> begin
>>    icon := TIcon.Create;
>>    S := 'This is a menu item';
>>    ImageList1.GetIcon(1, icon);
>>    cbxLocation.Items.AddObject(S, icon);
>> end;

>> the icon doesn't get added, but the string S does. What am I doing wrong?
>How
>> do I get both the string and the icon in cbxLocation? As a side note, the
>> ImageList has a combination of 16x16 and 32x32 icons, some of them
>designed
>> using the Image Editor.

>> PJK

Other Threads