 |
| Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 23rd, 2004, 06:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Columnheader Icon, Alignment Property
I seem to be in a bit of a jam. I am wanting to use the alignment property and display and icon in a column header for a listview control. It appears that the Icon property sets the Alignment property to Left Align. There must be some way to override this.
Any help would be greatly appreciated.
Larry Asher
__________________
Larry Asher
|
|

March 23rd, 2004, 09:20 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are right, setting the icon will change the column alignment.
Fortunatelly there is a solution, that is to set the column header item directly bypassing the vb call. You have to use the SendMessage API, passing a HDITEM parameter with the HDM_SETITEM message. You can find lot of examples in the web, just goggle for HDITM HDM_SETITEM. Sorry that I cannot post my code.
Marco
|
|

March 24th, 2004, 08:37 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Marco,
Thanks for the reply. I had been looking through the MSDN stuff for a SendMessage example. I will do as you suggest and check google. The information you gave me will allow me to be more specific in my search and perhaps get better results.
If all else fails I now have a work around - not crazy about it but it works. It involves padding the string based on the alignment property value. But it can require a lot of unneeded string manipulation.
Thanks.
Larry Asher
|
|

March 24th, 2004, 03:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I agree, especially because padding works only with fixed size fonts... I'll see if I can found the original article I used to write my code.
Marco
|
|

March 24th, 2004, 04:36 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Marco,
I found a code sample and have it working with my program now. However, it still defaults to left align when an icon is added to the column header. This to me is a bit strange.
Here is the function I am using to display the icon. I was wondering if I need to pass another value. But, I can't seem to find it. My initial thought is I am overriding the alignment unknowingly in my code.
Public Sub ShowHeaderIcon(ByRef LV As ListView, ByVal ColNo As Long, _
ByVal IconNo As Long, ByVal ShowImage As Long)
Dim hHeader As Long
Dim HD As HD_ITEM
' Get a handle to the listview header component
hHeader = SendMessage(LV.hwnd, LVM_GETHEADER, 0, ByVal 0)
' Set up the required structure members
With HD
.mask = HDI_IMAGE Or HDI_FORMAT
.pszText = LV.ColumnHeaders(ColNo).Text
If ShowImage Then
.fmt = HDF_STRING Or HDF_IMAGE Or HDF_BITMAP_ON_RIGHT
.iImage = IconNo
Else
.fmt = HDF_STRING
End If
End With
' Modify the header
' We must subtract 1 from the column header index
Call SendMessage(hHeader, HDM_SETITEM, (ColNo - 1), HD)
End Sub
Once again I appreciate your help.
Larry Asher
|
|

March 24th, 2004, 07:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try adding HDF_RIGHT to .fmt
.fmt = .... OR HDF_RIGHT
PS the code you found is a little old, HD_ITEM has been superseded by HDITEM
Marco
|
|

March 24th, 2004, 08:50 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Marco,
Hats off to you! I added the HDF_LEFT, HDF_RIGHT, HDF_CENTERED and it works great. I have now scratched the fixed width font and the application looks tons better! Plus it is much more efficient.
Thanks very much.
Larry Asher
|
|

March 25th, 2004, 02:11 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No problem Larry, I'm glad it helped. I used those years ago API to enhance the ListView adding the sorting icons in the header, I am just surpised I even remembered me doing it...
m.
|
|
 |