Solved

CustomDraw in  ListView

Posted on 2002-07-21
1
926 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

22 Experts available now in Live!

Get 1:1 Help Now