Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6150947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:41:48+00:00 2026-05-23T19:41:48+00:00

how to extend this code: ListView in vsReport mode colouring of Items and rows

  • 0

how to extend this code: ListView in vsReport mode colouring of Items and rows to draw small icons?

and why do I have the error ‘List index out of bounds (2)’ if I have 3 columns?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:41:49+00:00Added an answer on May 23, 2026 at 7:41 pm

    There are many ways to draw the icons, depending on where they come frome (a file, a resource, a system icon, etc.) and depending on if there should be a single icon for all items or if every item has its own icon. Anyhow, the general idea should be clear from this extended version of the code in the previous question (and I have also fixed the out-of-bounds bug…):

    type
      TForm1 = class(TForm)
      ...
      private
        { Private declarations }
        bm: TBitmap;
      ...
      end;
    
    ...
    
    implementation
    
    ...
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      bm := TBitmap.Create;
      bm.LoadFromFile('C:\Users\Andreas Rejbrand\Desktop\img.bmp');
    end;
    
    procedure TForm1.ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
      Rect: TRect; State: TOwnerDrawState);
    var
      i: Integer;
      x1, x2: integer;
      r: TRect;
      S: string;
    const
      DT_ALIGN: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
    begin
      if Odd(Item.Index) then
      begin
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Brush.Color := $F6F6F6;
      end
      else
      begin
        Sender.Canvas.Font.Color := clBlack;
        Sender.Canvas.Brush.Color := clWhite;
      end;
      Sender.Canvas.Brush.Style := bsSolid;
      Sender.Canvas.FillRect(Rect);
      x1 := 0;
      x2 := 0;
      r := Rect;
      Sender.Canvas.Brush.Style := bsClear;
      Sender.Canvas.Draw(3, r.Top + (r.Bottom - r.Top - bm.Height) div 2, bm);
      for i := 0 to ListView1.Columns.Count - 1 do
      begin
        inc(x2, ListView1.Columns[i].Width);
        r.Left := x1;
        r.Right := x2;
        if i = 0 then
        begin
          S := Item.Caption;
          r.Left := bm.Width + 6;
        end
        else
          S := Item.SubItems[i - 1];
        DrawText(Sender.Canvas.Handle,
          S,
          length(S),
          r,
          DT_SINGLELINE or DT_ALIGN[ListView1.Columns[i].Alignment] or
            DT_VCENTER or DT_END_ELLIPSIS);
        x1 := x2;
      end;
    end;
    

    Screenshot

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
I have this Code to Capture a image and Display it back in ListView
I'm following the List View tutorial and I have this code (very minor modifications):
I got this code: (function($){ var ListView = Backbone.View.extend({ el: $('body'), // el attaches
I have this code: public class Window extends JFrame { public Window(){ ... JButton
Why do I get compiler errors with this Java code? 1 public List<? extends
I have a listview which populates its content from SQLite Database. Here's my code:
I have no idea why I'm getting it on this line of code (where
I have this code but I am unable to find out how it is
my class extends Activity, not ListActivity. i have this code on create method but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.