Putting sort-direction arrows on listview columnheaders.
Author |
Message |
Dave #1 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Hello, I have some listviews in my project that I use in Report view. I am allowing the users to sort them by clicking on the columnheaders. Each successive click on the same columnheader reverses the sort-order. I was wondering if there is a way that I can put arrows on the columnheaders that show the sort-direction like the ones in the Windows Explorer details view. Much thanks for any input. -- David A. Frischknecht http://www.*-*-*.com/
|
Fri, 01 Apr 2005 23:31:03 GMT |
|
 |
Frank Ad #2 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Quote:
>Hello, >I have some listviews in my project that I use in Report view. I am >allowing the users to sort them by clicking on the columnheaders. Each >successive click on the same columnheader reverses the sort-order. I was >wondering if there is a way that I can put arrows on the columnheaders that >show the sort-direction like the ones in the Windows Explorer details view. >Much thanks for any input.
That's done with the ColumnHeader's icons. You need to place an ImageList and find or make some icons that'll suit your purposes.. ..\Common\Graphics\Icons have a fair few icons in them to pick from. Once you have the ImageList set up, then you can bind it to the ListView in it's property page. Look for ImageLists tab and Columnheaders in there somwehere. Then for each column header you assign the icon's index. So in this case you'd have an "up"(1) and "down"(2) arrows. Assign 1 to the column's icon, then when the sorting changes assign the other icon with LV.ColumnHeaders( col) .Icon = 2 Hope that makes sense, many beers and early hours here. :) -- Regards, Frank
|
Fri, 01 Apr 2005 23:53:53 GMT |
|
 |
Dave #3 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Thanks for the info. However, I'd like to know if there's a way that I can get the icons to show on the right side of the columnheader. -- David A. Frischknecht http://fishnetonline.tripod.com
Quote:
> >Hello, > >I have some listviews in my project that I use in Report view. I am > >allowing the users to sort them by clicking on the columnheaders. Each > >successive click on the same columnheader reverses the sort-order. I was > >wondering if there is a way that I can put arrows on the columnheaders that > >show the sort-direction like the ones in the Windows Explorer details view. > >Much thanks for any input. > That's done with the ColumnHeader's icons. > You need to place an ImageList and find or make some icons that'll > suit your purposes.. ..\Common\Graphics\Icons have a fair few icons > in them to pick from. > Once you have the ImageList set up, then you can bind it to the > ListView in it's property page. Look for ImageLists tab and > Columnheaders in there somwehere. Then for each column header you > assign the icon's index. > So in this case you'd have an "up"(1) and "down"(2) arrows. > Assign 1 to the column's icon, then when the sorting changes assign > the other icon with LV.ColumnHeaders( col) .Icon = 2 > Hope that makes sense, many beers and early hours here. :) > -- > Regards, Frank
|
Sat, 02 Apr 2005 03:50:11 GMT |
|
 |
Tony #4 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Quote:
>Thanks for the info. >However, I'd like to know if there's a way that I can get the icons to show >on the right side of the columnheader.
Go to http://www.mvps.org/vbnet/ Select code library from the left hand side menu. Select common ctrls from the menu at the top of the right hand side of the screen. Scroll down to the article titled "How to Add Images to a ListView Header". There's some sample code that shows you how to put a sort direction arrow to the right of the listview header text. Tony
|
Sat, 02 Apr 2005 13:29:58 GMT |
|
 |
Dave #5 / 8
|
 Putting sort-direction arrows on listview columnheaders.
That code doesn't work for me since I'm using the version of the ListView control that ships with VB 6. -- David A. Frischknecht http://fishnetonline.tripod.com
Quote:
> >Thanks for the info. > >However, I'd like to know if there's a way that I can get the icons to show > >on the right side of the columnheader. > Go to http://www.mvps.org/vbnet/ > Select code library from the left hand side menu. > Select common ctrls from the menu at the top of the right hand side of > the screen. > Scroll down to the article titled "How to Add Images to a ListView > Header". > There's some sample code that shows you how to put a sort direction > arrow to the right of the listview header text. > Tony
|
Sat, 02 Apr 2005 21:29:05 GMT |
|
 |
Tony #6 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Quote:
>That code doesn't work for me since I'm using the version of the ListView >control that ships with VB 6.
You can still use the SendMessage technique specified in the article to force the bitmap to appear to the right of the column header. I successfully borrowed the techniques specified in the article in one of my own projects, and I use the version of Mscomctl.ocx that comes with VB6, Service Pack 5. Here's a snippet of code from my project that I used to do the bitmap alignment. This is not the entire routine, but it should be enough to show the general idea. I apologize if the wrapping is off-kilter. Private Sub lvwAttachments_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader) Dim intIcon As Integer 'icon index in ImageList control Dim lngReturnValue As Long Dim objHeaderItem As HD_ITEM 'Set Sort Order And Icon For Clicked Column If lvwAttachments.SortKey <> ColumnHeader.Index - 1 Then 'Different Sort Column - Ascending By Default lvwAttachments.SortOrder = lvwAscending intIcon = 1 Else 'Same Sort Column - Change Current Sort Order If lvwAttachments.SortOrder = lvwAscending Then lvwAttachments.SortOrder = lvwDescending intIcon = 2 Else lvwAttachments.SortOrder = lvwAscending intIcon = 1 End If End If 'Remove Sort Order Icon From Previous Sort Column lngReturnValue = SendMessage(lvwAttachments.hWnd, LVM_GETHEADER, _ 0, ByVal 0) With objHeaderItem .mask = HDI_FORMAT .pszText = lvwAttachments.ColumnHeaders( _ lvwAttachments.SortKey + 1).Text .fmt = HDF_STRING End With Call SendMessage(lngReturnValue, HDM_SETITEM, _ lvwAttachments.SortKey, objHeaderItem) 'Force Sort Order Icon To Be To The Right Of The Column Caption lngReturnValue = SendMessage(lvwAttachments.hWnd, LVM_GETHEADER, _ 0, ByVal 0) With objHeaderItem .mask = HDI_IMAGE Or HDI_FORMAT .pszText = lvwAttachments.ColumnHeaders(ColumnHeader.Index).Text .fmt = HDF_STRING Or HDF_IMAGE Or HDF_BITMAP_ON_RIGHT .iImage = intIcon - 1 End With Call SendMessage(lngReturnValue, HDM_SETITEM, _ ColumnHeader.Index - 1, objHeaderItem) Tony
|
Sun, 03 Apr 2005 02:07:50 GMT |
|
 |
Dave #7 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Thank you so much for the help. That is exactly what I wanted. :-D -- David A. Frischknecht http://fishnetonline.tripod.com
Quote:
> >That code doesn't work for me since I'm using the version of the ListView > >control that ships with VB 6. > You can still use the SendMessage technique specified in the article > to force the bitmap to appear to the right of the column header. I > successfully borrowed the techniques specified in the article in one > of my own projects, and I use the version of Mscomctl.ocx that comes > with VB6, Service Pack 5. > Here's a snippet of code from my project that I used to do the bitmap > alignment. This is not the entire routine, but it should be enough to > show the general idea. I apologize if the wrapping is off-kilter. > Private Sub lvwAttachments_ColumnClick(ByVal ColumnHeader As > MSComctlLib.ColumnHeader) > Dim intIcon As Integer 'icon index in ImageList control > Dim lngReturnValue As Long > Dim objHeaderItem As HD_ITEM > 'Set Sort Order And Icon For Clicked Column > If lvwAttachments.SortKey <> ColumnHeader.Index - 1 Then > 'Different Sort Column - Ascending By Default > lvwAttachments.SortOrder = lvwAscending > intIcon = 1 > Else > 'Same Sort Column - Change Current Sort Order > If lvwAttachments.SortOrder = lvwAscending Then > lvwAttachments.SortOrder = lvwDescending > intIcon = 2 > Else > lvwAttachments.SortOrder = lvwAscending > intIcon = 1 > End If > End If > 'Remove Sort Order Icon From Previous Sort Column > lngReturnValue = SendMessage(lvwAttachments.hWnd, LVM_GETHEADER, _ > 0, ByVal 0) > With objHeaderItem > .mask = HDI_FORMAT > .pszText = lvwAttachments.ColumnHeaders( _ > lvwAttachments.SortKey + 1).Text > .fmt = HDF_STRING > End With > Call SendMessage(lngReturnValue, HDM_SETITEM, _ > lvwAttachments.SortKey, objHeaderItem) > 'Force Sort Order Icon To Be To The Right Of The Column Caption > lngReturnValue = SendMessage(lvwAttachments.hWnd, LVM_GETHEADER, _ > 0, ByVal 0) > With objHeaderItem > .mask = HDI_IMAGE Or HDI_FORMAT > .pszText = lvwAttachments.ColumnHeaders(ColumnHeader.Index).Text > .fmt = HDF_STRING Or HDF_IMAGE Or HDF_BITMAP_ON_RIGHT > .iImage = intIcon - 1 > End With > Call SendMessage(lngReturnValue, HDM_SETITEM, _ > ColumnHeader.Index - 1, objHeaderItem) > Tony
|
Sun, 03 Apr 2005 02:35:24 GMT |
|
 |
Tony #8 / 8
|
 Putting sort-direction arrows on listview columnheaders.
Quote:
>Thank you so much for the help. That is exactly what I wanted. :-D
Glad to be of help.
|
Sun, 03 Apr 2005 05:05:55 GMT |
|
|
|