Solved

CustomDraw in  ListView

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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