Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 23rd, 2004, 06:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: McPherson, Kansas, USA.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old March 23rd, 2004, 09:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old March 24th, 2004, 08:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: McPherson, Kansas, USA.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old March 24th, 2004, 03:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old March 24th, 2004, 04:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: McPherson, Kansas, USA.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old March 24th, 2004, 07:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #7 (permalink)  
Old March 24th, 2004, 08:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: McPherson, Kansas, USA.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old March 25th, 2004, 02:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
place the checkbox in Columnheader noornmd C# 2005 0 July 30th, 2008 02:12 AM
Alignment of ContentPlaceHolder garak0410 ASP.NET 2.0 Basics 2 June 7th, 2006 12:06 PM
alignment p_gauri7 Crystal Reports 0 May 9th, 2005 01:16 PM
how to set COM object icon property in VIS pritz VB How-To 0 March 28th, 2005 04:30 AM
text-alignment anshul HTML Code Clinic 5 July 18th, 2004 01:49 PM



All times are GMT -4. The time now is 09:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.