Solved

CustomDraw in  ListView

Posted on 2002-07-21
1
916 Views
Last Modified: 2007-11-27
I use ListView. The viewstyle property is set to vsReport.
The data displated on Listview may like:

Item    Qty    Amt     Status      Desc
1011    100    20.00      S        abcdef
1022     20    100.00     D        dahfdsf

I want to customizing the appearance of data according to the data value. For example, if Status is 'S', I may display it as 'In Stock' rather than 'S', and also able to change its font and the background color. If possible I would like change item's font, backgroud color, and text as well depends Status' value.

How can I do these?


Thank u very much.

peter
0
Comment
Question by:petershaw9
1 Comment
 
LVL 3

Accepted Solution

by:
Slavak earned 100 total points
Comment Utility
just place the code to OnCustomDrawSubItem event:

example:

procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);

Var
  S     : String;
  R     : TRect;
  C     : TColor;
  I     : Integer;

begin
 DefaultDraw := (SubItem - 1) <> 2;
 If DefaultDraw Then
   Exit;

 With TListView(Sender) Do Begin
   Case Item.SubItems[SubItem - 1][1] of
     'S' : Begin
             S := 'In stock';
             C := clGreen;
           End;
     'D' : Begin
             S := 'Not in stock';
             C := clRed;
           End;
     Else Begin
       S := Item.SubItems[SubItem];
       C := clBlack;
     End;
   End;

   R.Left := 0;
   For I := 0 To SubItem - 1 Do
     R.Left := R.Left + Columns[I].Width;

   R.Right  := R.Left + Columns[SubItem - 1].Width;
   R.Top    := Item.Top;
   R.Bottom := R.Top + 20;

   Canvas.Font.Color := C;
   Canvas.TextOut(R.Left, R.Top, S);
 End;
end;


But, if you can, prefered to place right string already in the SubItems, so the function can be much more clear.

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

16 Experts available now in Live!

Get 1:1 Help Now