Solved

How can I change the height of a listview header?

Posted on 2010-09-13
12
1,496 Views
Last Modified: 2012-05-10
Hi,

How can I change the height of a listview header?
I have searched on the internet, but didn't find anyting
that made sense.

Who can help me?

Peter Kiers
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
  • 6
  • 5
12 Comments
 
LVL 12

Accepted Solution

by:
Hypo earned 500 total points
ID: 33666391
try this code... It resets itself when you resize columns, but at least it's a good start...

/Hypo
procedure TForm1.SetListViewHeaderHeight(AListView : TListView; AHeight : integer);
var aHeaderHandle: HWND;
    aLayout: _HD_LAYOUT;
    aRect: TRect;
    aWindowPos: tagWINDOWPOS;
begin
  // Get header to handle...
  aHeaderHandle := ListView_GetHeader(AListView.Handle);
  //
  aRect := AListView.ClientRect;
  // Setup HeaderLayout...
  aLayout.Rect := @aRect;
  aLayout.WindowPos := @aWindowPos;
  // Get header metrics...
  if not Header_Layout(aHeaderHandle, @aLayout) then
    RaiseLastOSError;
  // Resize the header...
  SetWindowPos(aHeaderHandle,
               aWindowPos.hwndInsertAfter,
               aWindowPos.x,
               aWindowPos.Y,
               aWindowPos.cx,
               AHeight,
               aWindowPos.flags);
  // Repaint the header...
  InvalidateRect(aHeaderHandle, nil, true);
end;

Open in new window

0
 
LVL 24

Expert Comment

by:jimyX
ID: 33669462
I have had similar issue long time ago. What I did is that I created two ListViews, one showing only the header on top of the other that has hidden header (see the attached pic).
In the Columns Editor I set the Minwidth, Maxwidth, and the Width of the columns of the Header ListView to be equivalent to the width of the second ListView columns to prevent the header columns of being re-sized so not to lose the columns' structure.

But if re-sizing the columns is necessary all you have to do is capturing the column resizing event at the Header ListView then re-size the other one to keep the respective columns in the same width.

To capture a column re-size event:
http://www.swissdelphicenter.ch/torry/showcode.php?id=1264

JG
Listview-e.g.bmp
0
 
LVL 12

Expert Comment

by:Hypo
ID: 33669618
btw. I see now that I forgot to include the required uses clause... I think the example I provided requires CommCtrl, ComCtrls apart from the usual standard units. (can't try it right now)
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 1

Author Comment

by:peterkiers
ID: 33669650
I am trying HYPO's solution now, and i get a few errors:

  [Pascal Error] Main.pas(89): E2003 Undeclared identifier: '_HD_LAYOUT'
  [Pascal Error] Main.pas(94): E2003 Undeclared identifier: 'ListView_GetHeader'
  [Pascal Error] Main.pas(98): E2010 Incompatible types: 'TRect' and 'Pointer'
  [Pascal Error] Main.pas(101): E2003 Undeclared identifier: 'Header_Layout'

Is there something that I should declare at uses?

P.
0
 
LVL 12

Expert Comment

by:Hypo
ID: 33669663
What version of Delphi do you use?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33669677
How can I call for this procedure and I want to change the height of the panels to 19.
Where in the code should I put 19.
0
 
LVL 12

Expert Comment

by:Hypo
ID: 33669680
Yep, with Delphi 6, all I have to add is the CommCtrl unit to the uses clause... try that and it should work.

/Hypo
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33669687
Borland Developer Studio 2006
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33669691
CommCtrl works
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33669694
How can I call for this procedure and I want to change the height of the panels to 19.
Where in the code should I put 19.
0
 
LVL 12

Expert Comment

by:Hypo
ID: 33669712
I made a small example in a button... just setup a list view on your form, then add a button, and try it out...

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetListViewHeaderHeight(ListView1, 19 {HERE IS WHERE YOU PUT YOUR HEIGHT});
end;

I think you should be able to use it in one of the resize events... But I'll have to check if there are any issues with putting it there first...

/Hypo
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33669783
Your solution works fine.

Greetings, Peter Kiers
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 61
CheckListBox usage 3 81
Add New Database Table in database file using delphi 3 27
Firemonkey Listview item popup menu ? 1 26
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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