Jump to content

Sort a List View alphabetically when column header is clicked?


Recommended Posts

Sorry if that post was confusing, I'm figuring out new stuff as I type. LOL. But it's all a learning experience right?

Hi

Very interested in this topic

Some nice information here. But wondering why this relatively obscure UDF that is not in the helpfile. Why not use

_GUICtrlListView_SimpleSort

I found it in the function in a third party online help file. I assume it is in the UDF.chm file as well.

Link to comment
Share on other sites

Hi again

Your examples work, The function works when I transfer it to my script, however the case switch does not work and won't register the click on the header.

When you look at the simple sort example it registers the click on the column heading using the following:

CODE
Switch $hWndFrom

Case $hWndListView

Switch $iCode

Case $LVN_COLUMNCLICK ; A column was clicked

$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

_DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _

"-->IDFrom:" & @TAB & $iIDFrom & @LF & _

"-->Code:" & @TAB & $iCode & @LF & _

"-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _

"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _

"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _

"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _

"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _

"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _

"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _

"-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))

_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))

; No return value

So, I'm pretty confused how the below switch in your script works. Case $ListView. That just means the listview is selected doesn't it?

CODE
While 1

Switch GUIGetMsg() ;wait for input

Case $GUI_EVENT_CLOSE

_GUICtrlListView_UnRegisterSortCallBack($ListView)

Exit

Case $ListView

_GUICtrlListView_SortItems($ListView, GUICtrlGetState($ListView)) ;BOOM!

EndSwitch

WEnd

What am I missing, why doesn't your switch work in my script.....do I need to apply the Case $LVN_COLUMNCLICK

Picea

Link to comment
Share on other sites

Hi again

Your examples work, The function works when I transfer it to my script, however the case switch does not work and won't register the click on the header.

When you look at the simple sort example it registers the click on the column heading using the following:

CODE
Switch $hWndFrom

Case $hWndListView

Switch $iCode

Case $LVN_COLUMNCLICK ; A column was clicked

$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

_DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _

"-->IDFrom:" & @TAB & $iIDFrom & @LF & _

"-->Code:" & @TAB & $iCode & @LF & _

"-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _

"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _

"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _

"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _

"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _

"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _

"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _

"-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))

_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))

; No return value

So, I'm pretty confused how the below switch in your script works. Case $ListView. That just means the listview is selected doesn't it?

CODE
While 1

Switch GUIGetMsg() ;wait for input

Case $GUI_EVENT_CLOSE

_GUICtrlListView_UnRegisterSortCallBack($ListView)

Exit

Case $ListView

_GUICtrlListView_SortItems($ListView, GUICtrlGetState($ListView)) ;BOOM!

EndSwitch

WEnd

What am I missing, why doesn't your switch work in my script.....do I need to apply the Case $LVN_COLUMNCLICK

Picea

I am not using SimpleSort, instead SortItems. Honestly the SimpleSort function isn't so simple in my opinion.

When a header is clicked, GUIGetMsg() will return the control ID of the list view, and from there you can use GUICtrlGetState($ListView) to find out which header was clicked.

In fact, $LVN_COLUMNCLICK does not appear at all in my script.

If GUIGetMsg() = $ListView Then ;a header was clicked
$ListView_HeaderClicked =  GUICtrlGetState($ListView) ;find out which one was clicked, the header clicked now equals $ListView_HeaderClicked
MsgBox("", "You clicked: " & $ListView_HeaderClicked)
EndifoÝ÷ Ù*2¢íýÛhv®¶­sevÆR¥7vF6uTvWD×6r·vBf÷"çW@ 66Rb33c´uTôUdTåEô4Äõ4P W@ 66Rb33c´Æ7EfWp ôuT7G&ÄÆ7EfWuõ6÷'DFV×2b33c´Æ7EfWrÂuT7G&ÄvWE7FFRb33c´Æ7EfWr´$ôôÒb333°¤VæE7vF6¥tVæ@

to get which header was clicked.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...