Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add a small image on each listbox line?

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

730 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