Solved

CustomDraw in  ListView

Posted on 2002-07-21
1
940 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
ID: 7167916
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

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