Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to highlight alternate rows in a TListView Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
124
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to highlight alternate rows in a TListView

Answer:

The following will draw all alternate lines with yellow text on blue background. It 
uses the OnAdvancedCustomDraw events of the listview. As a bonus you get full 
highlighting of selected lines.
1   
2   procedure CheckPaintstage(Stage: TCustomDrawStage; itemIndex: Integer; canvas:
3     TCanvas);
4   begin
5     if Stage in [cdPrePaint, cdPreErase] then
6     begin
7       if Odd(itemIndex) then
8       begin
9         Canvas.Brush.Color := clBlue;
10        if Stage = cdPrepaint then
11          Canvas.Font.color := clYellow;
12      end
13    end;
14  end;
15  
16  procedure TForm1.ListView1AdvancedCustomDrawItem(Sender: TCustomListView;
17    Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;
18    var DefaultDraw: Boolean);
19  begin
20    if not (cdsSelected in State) then
21      CheckPaintstage(Stage, item.Index, sender.canvas)
22    else
23      Sender.Canvas.Brush.Color := clHighlight;
24  end;
25  
26  procedure TForm1.ListView1AdvancedCustomDrawSubItem(Sender: TCustomListView;
27    Item: TListItem; SubItem: Integer; State: TCustomDrawState; Stage: 
28  TCustomDrawStage;
29    var DefaultDraw: Boolean);
30  begin
31    if not (cdsSelected in State) then
32      CheckPaintstage(Stage, item.Index, sender.canvas)
33    else
34    begin
35      Sender.Canvas.Font.Color := clHighlightText;
36      Sender.Canvas.Brush.Color := clHighlight;
37    end;
38  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC