Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add a small image on each listbox line?

Posted on 2001-07-10
4
Medium Priority
?
223 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses

926 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