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
ow to Display a sort order indicator in the column header of 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
31-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
170
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How can I display a sort order arrow on the tiltle row in TListView control (on the 
right side of the column caption)?

Answer:

The easiest way would be to add the arrow picture to the imagelist, assign it to 
the listview's smallimages property and specify the image index to the column 
(ImageIndex property of the TListColumn). Now you'll see the picture on the left 
side of the column header.

Another approach would be to draw the header by yourself. In case you're working 
with the standard (not overridden)TListView control, you can set the new window 
proc to the header in the form's OnCreate event. In the new header's window 
procedure you can check up if the WM_PAINT message is coming and perform custom 
drawing for the header or its part. See the example below for details:

1   { ... }
2   type
3     TForm1 = class(TForm)
4       ListView1: TListView;
5       { ... }
6     protected
7       FHeader: longint;
8       FOldWndProc: pointer;
9       procedure HeaderWndProc(var message: TMessage);
10    end;
11  
12  procedure TForm1.FormCreate(Sender: TObject);
13  begin
14    FHeader := ListView_GetHeader(ListView1.Handle);
15    FOldWndProc := Pointer(GetWindowLong(FHeader, GWL_WNDPROC));
16    SetWindowLong(FHeader, GWL_WNDPROC,
17      integer(Classes.MakeObjectInstance(HeaderWndProc)));
18  end;
19  
20  procedure TForm1.HeaderWndProc(var message: TMessage);
21  var
22    XCanvas: TCanvas;
23    XDC: HDC;
24    XSizeRect: TRect;
25  begin
26    if Assigned(FOldWndProc) then
27      message.Result := CallWindowProc(FOldWndProc, FHeader, message.Msg,
28        message.WParam, message.LParam);
29    case message.Msg of
30      WM_PAINT:
31        begin
32          XCanvas := TCanvas.Create;
33          XDC := GetWindowDC(FHeader);
34          try
35            XCanvas.Handle := XDC;
36            Windows.GetClientRect(FHeader, XSizeRect);
37            XCanvas.Brush.Color := clRed;
38            XCanvas.FillRect(XSizeRect);
39            {draw the new header's content here...}
40          finally
41            ReleaseDC(FHeader, XDC);
42            XCanvas.Free;
43          end;
44        end;
45    end;
46  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