Solved

Add a small image on each listbox line?

Posted on 2001-07-10
4
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

617 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