Solved

How can I change the height of a listview header, part2

Posted on 2010-09-15
6
1,443 Views
Last Modified: 2012-05-10
Hi,

I have asked this question before and received good solutions.
I have tried them all, except for one solution there I got stuck.
I wanted to try Espasquier's solution:

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_26471490.html
(the last post)

So I have put the code that Espasquier posted in my component.
And then tried to check it out by calling it dynamicly:

procedure TMainForm.Button1Click(Sender: TObject);
var
  MyListv: PkListv;
  MyListCol : TListColumn;
begin
  MyListv:= PkListv.Create(Self);
  MyListv.Parent := self;
  MyListv.Align := alTop;
  MyListv.Height := 300;
  MyListv.ViewStyle := vsReport;
  MyListv.GridLines := True;
  MyListv.ColumnClick := False;  
// MyListv.Caption:=IntToStr(MyListv.HeaderHeight);  <=============
  MyListv.HeaderHeight:=40;
  MyListCol := MyListv.Columns.Add;
  MyListCol.Alignment := taLeftJustify;
  MyListCol.Width := 150;
  MyListCol.Caption := 'Naam';
end;

But I get an error at line where I have put the arrow:

[Pascal Error] Main.pas(49): E2362 Cannot access protected symbol TControl.Caption

What do I do wrong?

Peter
My component:

unit PkListView;

interface

uses
  SysUtils, Classes, Controls, ComCtrls, Windows;

type
  PkListv = class(TListView)
  private
    { Private declarations }
  protected
    { Protected declarations }
   FHeaderHandle: HWND;
   function GetHeaderHeight:Integer;
   procedure SetHeaderHeight(h:Integer);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent);
    destructor Destroy();
  published
    { Published declarations }
   property HeaderHeight:Integer read GetHeaderHeight write SetHeaderHeight;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [PkListv]);
end;

{ PkListv }

const
  LVM_FIRST = $1000;
  LVM_GETHEADER = LVM_FIRST + 31;

constructor PkListv.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

end;

destructor PkListv.Destroy;
begin
  inherited;
end;

function PkListv.GetHeaderHeight: Integer;
Var
  Rc:TRect;
begin
 Result:=0;
 FHeaderHandle:=SendMessage(Handle, LVM_GETHEADER, 0, 0);
 If GetWindowRect(FHeaderHandle, rc)
  Then Result := rc.Bottom - rc.Top
end;

procedure PkListv.SetHeaderHeight(h: Integer);
begin
 FHeaderHandle:=SendMessage(Handle, LVM_GETHEADER, 0, 0);
 SetWindowPos( FHeaderHandle, 0 , 0, 0, Width, h, 0 );
 InvalidateRect(FHeaderHandle,nil,True);
end;

end.

Open in new window

0
Comment
Question by:peterkiers
[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
  • 3
  • 3
6 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 33680585
that line is useless, in my example it is the form caption that I set to the headerHeight converted
delete it and run !
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33680781
You mean this:

  MainForm.Caption:=IntToStr(MyListv.HeaderHeight);
  MyListv.HeaderHeight:=20;

After running it I get a number 0 in the caption of the mainform!

P
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33680816
Even only with this line:

  MyListv.HeaderHeight:=20;

its not working.



0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Accepted Solution

by:
epasquier earned 500 total points
ID: 33681113
can you try to change the Header Height on another event than the one that creates the LV ? I'm not sure that the Header window is created at this moment, and if so the Get/Set functions cannot work.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33681205
Yes, it works now, I have installed my component and called for it with a button.
And it works great. Just one little question remains:

If i resize the columns, the height of the header will be set to normal.
Is there something I could do about that, to prevent it. So I set the
header to 28, and I resize the columns that the header stays at 28.

P.
0
 
LVL 25

Expert Comment

by:epasquier
ID: 33682728
That is the problem, TListView has not been written to be easily subclassed.

A lot of such issues could be fixed by taking the TCustomList view code, and make the modification right from there. But as I told you in your first post, TListView sucks (both Microsoft implementation and Delphi wrapping) so it is better to take some replacements components from guys who spent years already to make their own improved versions
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 154
Sending files from  idTcpServer Socket to idTcpClient 2 65
How to add columns to a RAD Studio FMX grid at design time 1 60
IP without any Dots 1 99
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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