Solved

Add a small image on each listbox line?

Posted on 2001-07-10
4
213 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
Comment Utility

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
Comment Utility

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
Comment Utility
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
Comment Utility

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now