I took the code from the ListView Demo posting and worked it into my own project. Columns sort just fine but I cannot, for the life of me, figure out why the Up/Down arrows on the listview header are not showing up.
I make a call to ListViewSortColumn in listview LVN_COLUMNCLICK as below.
Function FORM_LISTVIEW_LVN_COLUMNCLICK ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
ByVal lpNMV As NM_LISTVIEW Ptr _ ' pointer to NM_LISTVIEW
) As Long
ListViewSortColumn (hWndControl,lpNMV)
End Function
Function ListViewSortColumn (hWndControl As Dword, ByVal lpNMV As NM_LISTVIEW Ptr) As Long
Local nListViewLastSortedColumn As Long
Local ListViewSortControl As ListView_Sort
SendMessage (hWndControl, %WM_SETREDRAW, %FALSE, 0)
' Listview TAG = Last sort order, TAG2 = Last sorted column
nListViewLastSortedColumn = Val (FF_Control_GetTag2 (hWndControl))
' Remove arrow on previously sorted column
If nListViewLastSortedColumn <> - 1 And _
nListViewLastSortedColumn <> @lpNMV.iSubItem Then
ShowHeaderArrow (hWndControl, nListViewLastSortedColumn, %SO_NONE)
End If
Select Case Val (FF_Control_GetTag2 (hWndControl))
Case @lpNMV.iSubItem
Select Case Val (FF_Control_GetTag (hWndControl))
Case %SO_ASCENDING
ListViewSortControl.SortOrder = %SO_DESCENDING
Case Else
ListViewSortControl.SortOrder = %SO_ASCENDING
End Select
Case Else
ListViewSortControl.SortOrder = %SO_ASCENDING
End Select
' Sort on selected column
ListViewSortControl.hWndControl = hWndControl
ListViewSortControl.Column = @lpNMV.iSubItem
ListView_SortItemsEx hWndControl, CodePtr(ListView_CompareFunc), VarPtr(ListViewSortControl)
' Draw arrow for selected column
ShowHeaderArrow (hWndControl, ListViewSortControl.Column, ListViewSortControl.SortOrder)
' Select first row of listview
FF_ListView_SetSelectedItem (hWndControl, 0)
' Save current sort option and column in listview TAG/TAG2
FF_Control_SetTag (hWndControl,Format$(ListViewSortControl.SortOrder))
FF_Control_SetTag2 (hWndControl,Format$(ListViewSortControl.Column))
ListView_EnsureVisible (hWndControl, 0, %FALSE)
SendMessage (hWndControl, %WM_SETREDRAW, %TRUE, 0)
FF_Control_Redraw hWndControl
End Function
Function ListView_CompareFunc (ByVal index1 As Long, ByVal index2 As Long, ByVal lpListViewSortControl As ListView_Sort Ptr) As Long
Local szItem1 As Asciiz * %MAX_PATH
Local szItem2 As Asciiz * %MAX_PATH
Local lNumeric1 As Double
Local lNumeric2 As Double
Local nReturn As Long
' Get the value from the ListView
ListView_GetItemText @lpListViewSortControl.hWndControl, index1, @lpListViewSortControl.Column, szItem1, %MAX_PATH
ListView_GetItemText @lpListViewSortControl.hWndControl, index2, @lpListViewSortControl.Column, szItem2, %MAX_PATH
' Determine what type of sort (Numeric or Character)
' Numeric
If IsNumeric(szItem1) And IsNumeric(szItem2) Then
lNumeric1 = Val(szItem1)
lNumeric2 = Val(szItem2)
If lNumeric1 < lNumeric2 Then
nReturn = -1
Else
If lNumeric1 > lNumeric2 Then
nReturn = +1
Else
nReturn = 0
End If
End If
Else
' Character
szItem1 = LTrim$(szItem1)
szItem2 = LTrim$(szItem2)
nReturn = Lstrcmpi(szItem1,szItem2)
End If
Function = IIF(@lpListViewSortControl.SortOrder = %SO_ASCENDING,nReturn,nReturn * -1)
End Function
Function ShowHeaderIcon (hWndControl As Dword, ByVal nColumn As Long, ByVal nSortOrder As Long) As Long
Local hHeader As Dword
Local HDI As HD_ITEM
hHeader = SendMessage(hWndControl, %LVM_GetHeader, 0, ByVal 0)
HDI.mask = %HDI_FORMAT
Header_GetItem (hHeader, nColumn, HDI)
Select Case nSortOrder
' Remove current up/down arrow
Case %SO_NONE
HDI.fmt = HDI.fmt And Not (%HDF_SORTDOWN Or %HDF_SORTUP)
Case %SO_ASCENDING
' Draws an up-arrow
HDI.fmt = HDI.fmt And Not %HDF_SORTDOWN
HDI.fmt = HDI.fmt Or %HDF_SORTUP
Case %SO_DESCENDING
' Draws a down-arrow
HDI.fmt = HDI.fmt And Not %HDF_SORTUP
HDI.fmt = HDI.fmt Or %HDF_SORTDOWN
End Select
Function = Header_SetItem (hHeader, nColumn, HDI)
End Function
Function IsNumeric (szAny As Asciiz * %MAX_PATH) As Long
If Verify(szAny, "0123456789.,+- ") = 0 Then Function = %TRUE Else Function = %FALSE
End Function
It's working for me...
But what I had to do to get it working was:
a) Download the ListView Demo. ;)
b) Add the missing Type Def:
Type ListView_Sort
hWndControl As Dword
Column As Dword
SortOrder As Dword
End Type
I used the "JPL_ListView_ComparePar" Type Def as a guide.
c) Change your call to "IsNumeric" (which didn't exist in your sample code) to "JPL_IsNumeric"
d) And of course comment out the original call to "JPL_ListView_ColumnToSort" and add your call to "ListViewSortColumn"
'Call JPL_ListView_ColumnToSort(hWndControl, lpNMV)
Call ListViewSortColumn (hWndControl,lpNMV)
Things work when I enable Theme support...sigh... :-\
You might of mentioned that earlier... ::)
Hmmm, it seems that "Theme Support" is underrepresented in the documentation department. ;)
But this link might help out.
http://www.planetsquires.com/protect/forum/index.php?topic=2103.msg16891#msg16891
I gave what the OP in the post that I referenced a try, and I got it to do something different (I'm not sure why enabling themes is an issue, but I'm primarily a linux guy so this isn't something that I've come across before).
This is what I did:
a) Added the include file located at: C:\Program Files\FireFly Visual Designer\CustomControls\Jose Roca\TB_XPButton\TB_XPButton.inc
b) added the lines:
Local junk As Long
junk = TB_XPButton_DisableTheming (ByVal HWND_FORM1_LISTVIEW1)
in:
"Function FORM1_WM_CREATE" (right below the other "Local" declarations.
Adding this stuff still requires that themes be enabled, but it does make for a more colorful listview display. ;)
So why is enabling theme support a problem? (usually I develop and test my FF & PB programs in linux, the only thing that doesn't work for me in linux is the help files).
Quote from: John Waalkes on December 26, 2010, 03:52:44 PM
You might of mentioned that earlier... ::)
It took me a bit of time to figure it out. After doing everything to the code I could figure out to check it, I took the Listview Demo code exactly as it was written and tried that without success. Then I checked every control setting...and then....I noticed that theme box checked.
I did update the code posted as it finally evolved - I put in a redraw pair to handle flickering and an EnsureVisible to force the listview to the top after a column sort.
Quote from: Richard Kelly on December 28, 2010, 01:11:06 AMIt took me a bit of time to figure it out. After doing everything to the code I could figure out to check it, I took the Listview Demo code exactly as it was written and tried that without success. Then I checked every control setting...and then....I noticed that theme box checked.
Oh, I wondered. :)
Quote from: Richard Kelly on December 28, 2010, 01:11:06 AMI did update the code posted as it finally evolved - I put in a redraw pair to handle flickering and an EnsureVisible to force the listview to the top after a column sort.
I'll have to play with it and see what you did. BTW, what are themes, and why are they important?