Solved

Add a small image on each listbox line?

Posted on 2001-07-10
4
216 Views
Last Modified: 2010-04-06

Is there a way to add a small image on each line of a listbox?  Or is there a better (memo?) way of doing the following?
I want to have a list of items in a listbox, one per line, and each item should have a small image to identify it, it may be something as simple as a folder icon to show a folder, just like windows explorer, or a different image which could be anything I want to identify.
A memo would also work, anything to list one item per line that is scrollable, so when I move the scroll bar up and down the names and images move together.

Anyone have any ideas on how to do this?

        Thanks
0
Comment
Question by:jexd99
  • 2
4 Comments
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6271033

Hello

The best component to use for this is a listview in report mode. With a listview you can associate an imagelist to it and it will draw bitmaps on each line. If you really wanted to use a listbox then you would need to do some custom drawing which is a bit trickier. I don't you can do what you want with a memobox.

If you want some sample code on using a listview, or doing custom drawing with a listbox then let me know.

regards

Jo
0
 
LVL 3

Accepted Solution

by:
nnbbb09 earned 100 total points
ID: 6271059

Here's some code for a listview anyway. Just drop a listview on your form and change its ViewStyle to vsReport. Edit the Columns property and add in as many columns as you want. Then drop an imagelist on the form and add in some bitmaps. Then set the ImageList property of the listview to equal the name of your Imagelist component.

procedure Tform1.PopulateListView;
var
  item : TListItem;
begin
  item := listview1.items.add;
  item.caption := 'A Caption';
 
  // if you want to add text to additonal columns then use this
  item.subitems.add('More text');

  item.imageindex:=0; // put the index from your imagelist here.

end;
0
 
LVL 2

Expert Comment

by:SChertkov
ID: 6272821
Set TListBox.Style property to lbOwnerDrawFixed, add ImageList that contain you images and add following OnDrawItem event

procedure TUserListForm.ListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  with TListBox(Control).Canvas do
    begin
      FillRect(Rect);
      ImageList1.Draw(TListBox(Control).Canvas, Rect.Left + 2, Rect.Top, 0); // Set you ImageIndex here
      Rect.Left := Rect.Left + 24;
      DrawText(TListBox(Control).Canvas.Handle,
        PChar(TListBox(Control).Items[Index]), -1, Rect, DT_VCENTER or DT_SINGLELINE);
    end;
end;

Also, this method come in useful for TComboBox

0
 

Author Comment

by:jexd99
ID: 6310900

Sorry to get back so late, I'm experimenting with this. :-)

I'm kinda new to the image list editor, but this is what I was looking for.

        Thanks to both of you
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 143
Press three keys together and trigger a function 3 56
Delphi...Split view - idea? 1 67
how to change, disabled button color FMX ? 1 32
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question