Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to make the panels of a listview flat?

Posted on 2010-09-12
5
Medium Priority
?
614 Views
Last Modified: 2012-05-10
Hi,

I have found code on the internet for making the panels of a listview flat.
But I don't know how to implement it? (what event etc.. etc...)
Can someone show me how? I have put the code in the code-section.

Greetings,

Peter Kiers


const
  LVM_GETHEADER = LVM_FIRST + 31;
var
  hHeader: THandle;
  style: dWord;
begin
  {to get the header handle for the listview}
  hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);

  {to get the current style attributes for the header}
  style := GetWindowLong(hHeader, GWL_STYLE);

  {to toggle the HDS_BUTTONS style}
  style := style xor HDS_BUTTONS;

  {to apply the new style}
  SetWindowLong(hHeader, GWL_STYLE, style);

  {to invalidate the listview}
  SetWindowPos(ListView1.Handle, Form1.Handle, 0, 0, 0, 0,
               SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME)
end;

Open in new window

0
Comment
Question by:peterkiers
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 33658390
That is ready to use code. Just start it on your form's FormCreate method. If it would not work there, then move it to FormShow method, but implement a simple "execute once" mechanism like that:

TForm1 = class()
 ....  
private
  FShownOnce: boolean;
end;

procedure Tform1.FormShow;
begin
  if not FShownOnce then
  begin
     //call mentioned above code
  end;
  FShownOnce := true;
end;

It will prevent code from executing each time form is shown.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33658407
I what event should i put the code that i have posted.

Peter
0
 
LVL 5

Accepted Solution

by:
Mechanic_Kharkov earned 2000 total points
ID: 33658486
In FormCreate.
DoubleClick on form, and Delphi will automatically create template for FormCreate method.
Just put this code there.

You'll get this code

procedure TForm1.FormCreate(Sender: TObject);
const
  LVM_GETHEADER = LVM_FIRST + 31;
var
  hHeader: THandle;
  style: dWord;
begin
  {to get the header handle for the listview}
  hHeader := SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);

  {to get the current style attributes for the header}
  style := GetWindowLong(hHeader, GWL_STYLE);

  {to toggle the HDS_BUTTONS style}
  style := style xor HDS_BUTTONS;

  {to apply the new style}
  SetWindowLong(hHeader, GWL_STYLE, style);

  {to invalidate the listview}
  SetWindowPos(ListView1.Handle, Form1.Handle, 0, 0, 0, 0,
               SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME)
end;

And don't forget to add to your Uses clause CommCtrl (there already is CommCtrls but it is a little different).
0
 
LVL 1

Author Comment

by:peterkiers
ID: 33658506
Perfect, it works great.

Greetings,

Peter Kiers
0
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 33658531
Thank You too for a nice piece of code, Peter. ;-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

877 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