Solved

CustomDraw in  ListView

Posted on 2002-07-21
1
942 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

623 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