How can I change the height of a listview header?


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
Peter KiersOperatorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try this code... It resets itself when you resize columns, but at least it's a good start...

procedure TForm1.SetListViewHeaderHeight(AListView : TListView; AHeight : integer);
var aHeaderHandle: HWND;
    aLayout: _HD_LAYOUT;
    aRect: TRect;
    aWindowPos: tagWINDOWPOS;
  // 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
  // Resize the header...
  // Repaint the header...
  InvalidateRect(aHeaderHandle, nil, true);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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:

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)
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Peter KiersOperatorAuthor Commented:
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?

What version of Delphi do you use?
Peter KiersOperatorAuthor Commented:
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.
Yep, with Delphi 6, all I have to add is the CommCtrl unit to the uses clause... try that and it should work.

Peter KiersOperatorAuthor Commented:
Borland Developer Studio 2006
Peter KiersOperatorAuthor Commented:
CommCtrl works
Peter KiersOperatorAuthor Commented:
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.
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);
  SetListViewHeaderHeight(ListView1, 19 {HERE IS WHERE YOU PUT YOUR HEIGHT});

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...

Peter KiersOperatorAuthor Commented:
Your solution works fine.

Greetings, Peter Kiers
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.