-
Sep 7th, 2016, 01:45 AM
#1
Thread Starter
Addicted Member
Column header click event in flat listview
Hello
For aesthetic reasons, the listviews in my program are made to look flat, and I had to use custom API calls to do that, because the "flat appearance" property in VB6 does not work.
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nindex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nindex As Long, ByVal dwNewLong As Long) As Long
Public Sub flattenLvHeader(ByRef lv As Object)
' hSysHeader = FindWindowEx(lv.hWnd, 0, "SysHeader32", vbNullString) ' For VB5 listviews
hSysHeader = FindWindowEx(lv.hWnd, 0, "msvb_lib_header", vbNullString) ' For VB6 listviews
SetWindowLong hSysHeader, GWL_STYLE, GetWindowLong(hSysHeader, GWL_STYLE) And Not HDS_BUTTONS
End Sub
(...)
Call flattenLvHeader(ListView1)
However, that prevents the event from firing when the user clicks on a listview header, and I need that event to let the user sort the listview by clicking a column header.
Does anyone know how to make a listview look flat so that clicking on the column header still fires an event?
-
Sep 7th, 2016, 04:23 AM
#2
Re: Column header click event in flat listview
What version of listview you use?
- Microsoft Windows Common Controls 5.0 (SP2)
- Microsoft Windows Common Controls 6.0 (SP6)
-
Sep 7th, 2016, 04:26 AM
#3
Thread Starter
Addicted Member
Re: Column header click event in flat listview
Microsoft Windows Common Controls 6.0 (SP6)
-
Sep 7th, 2016, 08:07 AM
#4
Re: Column header click event in flat listview
See the HDS_FLAT flag
Header Control Styles (Windows)
https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
-
Sep 7th, 2016, 08:56 AM
#5
Thread Starter
Addicted Member
Re: Column header click event in flat listview
Can't say that I know what to do with that. Replacing HDS_BUTTONS with HDS_FLAT (which I found from one source only that it should be &H200, is that even correct?) makes the listview headers no longer flat.
-
Sep 7th, 2016, 09:11 AM
#6
Re: Column header click event in flat listview
Ah you need to understand how to set/unset Bits and Masking.
I suspect you just want to Or HDS_FLAT, but definitely try and figure out how to set bits, using VB.
Code:
SetWindowLong hSysHeader, GWL_STYLE, GetWindowLong(hSysHeader, GWL_STYLE) Or HDS_FLAT
-
Sep 7th, 2016, 09:24 AM
#7
Thread Starter
Addicted Member
Re: Column header click event in flat listview
Thank you, unfortunately that does not make the listview header flat as "And Not HDS_BUTTONS" does.
Code:
Private Const HDS_FLAT As Long = &H200
-
Sep 7th, 2016, 10:06 AM
#8
Re: Column header click event in flat listview
Your project must not be manifested for CC 6.0 ?
honestly I can't even get your FindWindow call to work.
Last edited by DEXWERX; Sep 7th, 2016 at 10:12 AM.
-
Sep 7th, 2016, 10:14 AM
#9
Thread Starter
Addicted Member
Re: Column header click event in flat listview
I don't know how a project is manifested for CC 6.0, but "Project > Components > Microsoft Windows Common Controls 6.0 (SP6)" is ticked, and if I try to untick it I get "Can't remove control or reference; in use", and I'm running it in Windows XP using "Windows Classic style", and the VBP file has:
Code:
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; mscomctl.ocx
What else should I check?
-
Sep 7th, 2016, 11:09 AM
#10
Re: Column header click event in flat listview
the code you posted doesn't work either. *shrugs*
-
Sep 7th, 2016, 11:14 AM
#11
Thread Starter
Addicted Member
Re: Column header click event in flat listview
The code I posted works just fine here. It also works in the compiled program when run on Windows XP, 7 and 10.
Uses these constants:
Code:
Private Const HDS_BUTTONS As Long = &H2
Private Const GWL_STYLE = -16
Private hSysHeader As Long
-
Sep 7th, 2016, 11:18 AM
#12
Re: Column header click event in flat listview
Hi OldClock,
Just to start, I always use the VB6 SP6 ListView as well (Microsoft Windows Common Controls 6.0 (SP6), mscomctl.ocx).
It sounds like you're determined to get it working with the ListView headers. But I'll share the way I've long done it. I assume you're using the ListView in "Report" mode.
I also often use the "Flat" mode for its appearance. I'm unclear why you say that doesn't work. It works fine for me. I suppose it does still leave the black single-pixel border around the control, and also the headers still have a 3D appearance, but the list itself is flat.
Here's a picture of how it looks for me:
Now, regarding clicking the headers, the ColumnClick event also works just fine. However, I'm not entirely sure why but long ago, I abandoned using the column headers. I always just turn them off. In their place, I use labels correctly placed above the columns. And sometimes, these labels are clickable, allowing me to do certain things to the listview (such as sort it, etc). I might even occasionally popup a context menu when the label is clicked.
Using labels does have a couple of downsides though. For one, you can't resize your column widths, or rearrange them. If you need these features, you'll need to stick with the listview column headers.
I just thought I'd provide information about my experiences with listview.
Regards,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Sep 7th, 2016, 12:07 PM
#13
Thread Starter
Addicted Member
Re: Column header click event in flat listview
Setting appearance to flat does indeed change something, but the effect is incomplete. One must manually change the column headers to look consistent.
Example working project:
https://filebin.net/o48wzeqbmx6oi84s
Screenshot:
https://filebin.net/o48wzeqbmx6oi84s...907_190407.png
Listview appearance from the left: 3D, flat, 3D and API-flattened, flat and API-flattened.
Unfortunately, the column header click event does not fire for the really flat listviews - 3 and 4.
Last edited by OldClock; Sep 7th, 2016 at 12:10 PM.
-
Sep 7th, 2016, 01:25 PM
#14
Re: Column header click event in flat listview
It may be possible with subclassing, but I can't figure out what messages and notifications are involved.
Last edited by DEXWERX; Sep 7th, 2016 at 01:29 PM.
-
Sep 8th, 2016, 02:39 AM
#15
Re: Column header click event in flat listview
Originally Posted by OldClock
Unfortunately, the column header click event does not fire for the really flat listviews - 3 and 4.
As explained in the Microsoft article Header Control Styles (post #4) about HDS_BUTTONS flag:
Each item in the control looks and behaves like a push button.
Of course, if you remove the HDS_BUTTONS, the listview will lost this feature, of course ColumnClick event doesn't fire anymore.
-
Jul 29th, 2021, 12:03 PM
#16
New Member
Re: Column header click event in flat listview
Has anyone found a solution for flat and clickable header?
-
Jul 30th, 2021, 10:09 AM
#17
Re: Column header click event in flat listview
You would be better off starting a new thread on the subject. There's a fair chance that this one won't get all that many views, and it never got to a solution anyways. You'll get more eyes on the question with a new thread.
My usual boring signature: Nothing
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|