Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Changing header style in a TListView control
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question: How can I change the style of the header in a TListView control?
Answer: Delphi's VCL does not provide this. You need to
- get the header handle for the listview
- read the current style attributes for the header
- modify a style
- apply the new style
- invalidate the listview (force a redraw)
See the code snipped below. The result is a 'flat' listview as shown in this screenshot on the left side:
 | |  | | unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
ListView2: TListView;
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
uses
CommCtrl;
procedure TForm1.FormCreate(Sender: TObject);
const
LVM_GETHEADER = LVM_FIRST+31;
var
hHeader: THandle;
Style: DWORD;
begin
hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);
Style := GetWindowLong(hHeader, GWL_STYLE);
Style := Style xor HDS_BUTTONS;
SetWindowLong(hHeader, GWL_STYLE, Style);
SetWindowPos(ListView1.Handle, Form1.Handle,
0, 0, 0, 0,
SWP_NOZORDER or SWP_NOSIZE or
SWP_NOMOVE or SWP_DRAWFRAME)
end;
end. | |  | |  |
Comments:
|
|
|
|
While setting the 'Style' property, is it possible to RIGHT_ALIGN the images in the cloumns header?
|
|