Ghost21 Posted December 2, 2010 Share Posted December 2, 2010 I have tried both options that I seem to have found the simplesort <-- Which should be called Complex sort and another one I saw that was like 5 lines... Complex one works but seems too crazy someone got somethign better ? _GUICtrlListView_RegisterSortCallBack($ListView) Case $ListView $ListView_HeaderClicked = GUICtrlGetState($ListView) _GUICtrlListView_SortItems($ListView,$ListView_HeaderClicked) I see the little triangles that come up but nothing is sorted ???? Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 2, 2010 Share Posted December 2, 2010 The example script in the help file under _GUICtrlListView_RegisterSortCallBack() works fine and sorts on the columns for which you click the header. How does that not work for you? The little bit of code you posted does not give any indication of your issue. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Ghost21 Posted December 2, 2010 Author Share Posted December 2, 2010 The example script in the help file under _GUICtrlListView_RegisterSortCallBack() works fine and sorts on the columns for which you click the header. How does that not work for you? The little bit of code you posted does not give any indication of your issue. Ok. So I have looked over the code that you recommened and see myself no reason why this f..ing thing won't work.. So here is more code. Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) $ListView = GUICtrlCreateListView("Domain Device|IP Address|Serial Number|Description|Mac Address", 272, 472, 1004, 237,-1,$iExWindowStyle) ;BitOR($GUI_SS_DEFAULT_LISTVIEW, $WS_HSCROLL, $WS_VSCROLL, $WS_BORDER), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) _GUICtrlListView_SetExtendedListViewStyle($ListView, $iExListViewStyle) _GUICtrlListView_RegisterSortCallBack($ListView,True,True) TCPStartup() ;*************************************************************************** While 1 $nMsg = GUIGetMsg(1) ; Use advanced parameter to get an array returned Switch $nMsg[1] ; First check which GUI sent the message Case $Form1 Switch $nMsg[0] ; Now check for the messages sent from $hGUI1 Case $GUI_EVENT_CLOSE _GUICtrlListView_UnRegisterSortCallBack($ListView) Exit Case $ListView _GUICtrlListView_SortItems($ListView,GUICtrlGetState($ListView)) EndSwitch EndSwitch WEnd As well the comment above about how does that work for you the sample script works.. So your answer is it works great thanks for asking ... The small amount of code is because I'm not submitting 4000+ lines of code.. Just the stuff that is valid to the problem that i'm having.. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 2, 2010 Share Posted December 2, 2010 (edited) You're doing it wrong, the example script uses the following to sort the listview, NOT a GUIGetMsg(). GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2 $hWndListView = $hListView $hWndListView2 = $hListView2 If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView, $hWndListView2 Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ; Kick off the sort callback _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Change the variables to what you're using for your listview and you should be good to go. Edited December 2, 2010 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 2, 2010 Share Posted December 2, 2010 Very few here are willing to go over 4000+ lines to find a problem. The usually expected method is to code a short reproducer script with just enough in it to be a complete, runnable demonstration of your issue. It is my experience that in trying to code a short demo that isolates the issue, you very often come across the problem. And even if that doesn't solve it, you get a running demo posted that people are willing to test and work with, making it much more likely you'll get the help you need. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Ghost21 Posted December 3, 2010 Author Share Posted December 3, 2010 (edited) Ok PsaltyDS here goes I have followed the PsaltyDS way and made a seperate script so you can get an idea of whats going on. ( WHERE I SCREWED UP... ) I have addded everything except the data that fills it and thats like this for example: PCname1 192.168.1.1 778993001 PC1 0011223344 PCname2 192.168.1.2 778993002 PC2 0011223344 PCname3 192.168.1.3 778993003 PC3 0011223344 PCname4 192.168.1.4 778993004 PC4 0011223344 PCname5 192.168.1.5 778993005 PC5 0011223344 ????????????????????????? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> GUICreate("ListView Sort",1004, 500) Global $ListView Global $oRS Global $oConn Global $DatabasePath = $path1 Global $Filelocation = $path2 Global $PsToolsFilelocation = $path3 Global $UtilsFilelocation = $path4 Global $ObjFullname[1][2] Global $MAC Global $count _test() func _Test() Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) $ListView = GUICtrlCreateListView("Domain Device|IP Address|Serial Number|Description|Mac Address",5, 100, 950, 237,-1,$iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($ListView, $iExListViewStyle) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 110) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 300) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 173) GUICtrlSetBkColor(-1, 0xA6CAF0) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) _GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView), 4, 2) _Fill() GUISetState() _GUICtrlListView_RegisterSortCallBack($Listview,True,True) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Listview _GUICtrlListView_SortItems($Listview, GUICtrlGetState($Listview)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($Listview) GUIDelete() EndFunc Func _Fill() Call("dbopen") $oRS.Open("SELECT * from Active2", $oConn, 1, 3) $count = 0 With $oRS If .Recordcount Then While Not .EOF $DomainDevice = $oRS.Fields("PC" ).Value $IPAddress = $oRS.Fields("IP" ).Value $SerialNumber = $oRS.Fields("SerialNumber" ).Value $Description = $oRS.Fields("Description" ).Value $MacAddress = $oRS.Fields("Mac" ).Value _GUICtrlListView_AddItem($ListView, $DomainDevice, 0) _GUICtrlListView_AddSubItem($ListView, $count, $IPAddress, 1) _GUICtrlListView_AddSubItem($ListView, $count, $SerialNumber, 2) _GUICtrlListView_AddSubItem($ListView, $count, $Description, 3) _GUICtrlListView_AddSubItem($ListView, $count, $MacAddress, 4) $count = $count + 1 .MoveNext WEnd EndIf EndWith $oConn.close Call("dbclose") EndFunc Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2 $hWndListView = $Listview If Not IsHWnd($Listview) Then $hWndListView = GUICtrlGetHandle($Listview) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func dbOpen() $oConn = ObjCreate("ADODB.Connection") $oRS = ObjCreate("ADODB.Recordset") If FileExists($DatabasePath & "sw.mdb") Then $oConn.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=" & $DatabasePath & "sw.mdb") Else MsgBox(0, "Database Not Found", "Please Install DataBase", 25) Exit EndIf EndFunc ;==>dbOpen Func dbClose() $oConn = 0 EndFunc ;==>dbClose Edited December 3, 2010 by Ghost21 Link to comment Share on other sites More sharing options...
BrewManNH Posted December 3, 2010 Share Posted December 3, 2010 This script won't run. First it uses a DB that we don't have access to, to create the LV, second you are using variables that aren't declared so it errors before it even runs. A working example is just that, working. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 3, 2010 Share Posted December 3, 2010 (edited) I give you points for trying. Note how this fixed version applies your sample data without reference to a DB we don't have (as BrewManNH pointed out): expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Global $aTestData[5] = ["PCname1|192.168.1.5|778993001|PC0|00112233FE", _ "PCname2|192.168.1.4|778993003|PC2|00112233BD", _ "PCname3|192.168.1.3|778993005|PC4|00112233AC", _ "PCname4|192.168.1.2|778993002|PC1|00112233F0", _ "PCname5|192.168.1.1|778993004|PC3|00112233E8"] Global $ListView Global $oRS Global $oConn Global $ObjFullname[1][2] Global $MAC Global $count GUICreate("ListView Sort", 1004, 500) _test() Func _Test() Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) $ListView = GUICtrlCreateListView("Domain Device|IP Address|Serial Number|Description|Mac Address", 5, 100, 950, 237, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($ListView, $iExListViewStyle) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 110) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 300) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 173) GUICtrlSetBkColor(-1, 0xA6CAF0) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) _GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView), 4, 2) _Fill() GUISetState() _GUICtrlListView_RegisterSortCallBack($ListView, True, True) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $ListView _GUICtrlListView_SortItems($ListView, GUICtrlGetState($ListView)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($ListView) GUIDelete() EndFunc ;==>_Test Func _Fill() For $n = 0 To UBound($aTestData) - 1 GUICtrlCreateListViewItem($aTestData[$n], $ListView) Next EndFunc ;==>_Fill Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2 $hWndListView = $ListView If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Ouila! Complete, short, self-contained, running demo. I edited your sample data to make it more variable, so you could see some effect from sorting on the different columns. Edited December 3, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Ghost21 Posted December 3, 2010 Author Share Posted December 3, 2010 This script won't run. First it uses a DB that we don't have access to, to create the LV, second you are using variables that aren't declared so it errors before it even runs. A working example is just that, working.Really... Figured you could look at it and see something wrong... I guess not one sec... Link to comment Share on other sites More sharing options...
Ghost21 Posted December 3, 2010 Author Share Posted December 3, 2010 Heres a "working" demo.. except for the sort part thats not working... expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> GUICreate("ListView Sort",1004, 500) Global $ListView _test() func _Test() Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) $ListView = GUICtrlCreateListView("Domain Device|IP Address|Serial Number|Description|Mac Address",5, 100, 950, 237,-1,$iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($ListView, $iExListViewStyle) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 110) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 300) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 173) GUICtrlSetBkColor(-1, 0xA6CAF0) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) _GUICtrlListView_JustifyColumn(GUICtrlGetHandle($ListView), 4, 2) _Fill() GUISetState() _GUICtrlListView_RegisterSortCallBack($Listview,True,True) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Listview _GUICtrlListView_SortItems($Listview, GUICtrlGetState($Listview)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($Listview) GUIDelete() EndFunc Func _Fill() $i = "" $count = "" $DomainDevice = "PC" $IPAddress = "192.168.1." $SerialNumber = "0000000" $Description = "PC" $MacAddress = "00:11:22:33:" for $i = 1 to 50 _GUICtrlListView_AddItem($ListView, $DomainDevice & Chr(Random(Asc("A"), Asc("Z"), 1)) & $count, 0) _GUICtrlListView_AddSubItem($ListView, $count, $IPAddress & $count, 1) _GUICtrlListView_AddSubItem($ListView, $count, $SerialNumber & $count, 2) _GUICtrlListView_AddSubItem($ListView, $count, $Description & Chr(Random(Asc("A"), Asc("Z"), 1)) & $count, 3) _GUICtrlListView_AddSubItem($ListView, $count, $MacAddress & $count, 4) $count = $count + 1 Next EndFunc Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2 $hWndListView = $Listview If Not IsHWnd($Listview) Then $hWndListView = GUICtrlGetHandle($Listview) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 3, 2010 Share Posted December 3, 2010 Uhm... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Ghost21 Posted December 3, 2010 Author Share Posted December 3, 2010 Uhm... The sorting... Link to comment Share on other sites More sharing options...
BrewManNH Posted December 3, 2010 Share Posted December 3, 2010 Well, I see the problem using his script, it won't sort. Although PsaltyDS your's does even though they use the same function.I found that changing part of the Fill() function to the following will work though:For $i = 1 To 50 GuiCtrlCreateListviewItem($DomainDevice & Chr(Random(Asc("A"), Asc("Z"), 1)) & $count & "|" & $IPAddress & $count &"|"& $SerialNumber & $count & "|" & $Description & Chr(Random(Asc("A"), Asc("Z"), 1)) & $count & "|" & $MacAddress & $count, $ListView) $count = $count + 1 NextFor some reason that I'm not aware of, using the _GUICtrlListView_AddItem( and _GUICtrlListView_AddSubItem( UDFs was causing the issue with the sorting. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Ghost21 Posted December 3, 2010 Author Share Posted December 3, 2010 Ok so in the data you posed and what I posted just before that there is virtually nothing different besides the data in the list view...and yours works and mine doesn't.... Link to comment Share on other sites More sharing options...
BrewManNH Posted December 3, 2010 Share Posted December 3, 2010 Ok so in the data you posed and what I posted just before that there is virtually nothing different besides the data in the list view...and yours works and mine doesn't.... The version PsaltyDS posted used GUICtrlCreateListviewItem whereas your's used _GUICtrlListView_AddItem( and _GUICtrlListView_AddSubItem( as I pointed out, they seem to be the issue with the sorting routine. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Ghost21 Posted December 3, 2010 Author Share Posted December 3, 2010 Ahh I seee. I have changed my script to add the items in the single line form and seems faster and alot less lines thanks.. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 3, 2010 Share Posted December 3, 2010 I'm still looking at this because it should work using all UDF functions for the ListView, but something doesn't work. I've already run a debug version of _GUICtrlListView_SortItems() and it is working perfectly, but something in the internally registered function __GUICtrlListView_Sort() is failing: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Global $aTestData[5] = ["PCname1|192.168.1.5|778993001|PC0|00112233FE", _ "PCname2|192.168.1.4|778993003|PC2|00112233BD", _ "PCname3|192.168.1.3|778993005|PC4|00112233AC", _ "PCname4|192.168.1.2|778993002|PC1|00112233F0", _ "PCname5|192.168.1.1|778993004|PC3|00112233E8"] Global $aColWidths[5] = [150, 110, 150, 300, 173] Global $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Global $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) Global $hGUI, $hLV $hGUI = GUICreate("ListView Sort", 1004, 500) $hLV = _GUICtrlListView_Create($hGUI, "Domain Device|IP Address|Serial Number|Description|Mac Address", 5, 100, 950, 237, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hLV, $iExListViewStyle) For $n = 0 To UBound($aColWidths) - 1 _GUICtrlListView_SetColumnWidth($hLV, $n, $aColWidths[$n]) Next _GUICtrlListView_SetBkColor($hLV, 0xA6CAF0) _GUICtrlListView_JustifyColumn($hLV, 4, 2) _Fill() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() _GUICtrlListView_RegisterSortCallBack($hLV, True, True) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($hLV) GUIDelete() Func _Fill() Local $aSplit For $n = 0 To UBound($aTestData) - 1 ; GUICtrlCreateListViewItem($aTestData[$n], $ListView) $aSplit = StringSplit($aTestData[$n], "|") _GUICtrlListView_AddItem($hLV, $aSplit[1]) For $s = 2 To $aSplit[0] _GUICtrlListView_AddSubItem($hLV, $n, $aSplit[$s], $s - 1) Next Next EndFunc ;==>_Fill Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) Local $iCol = DllStructGetData($tInfo, "SubItem") _GUICtrlListView_SortItems($hWndFrom, $iCol) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 3, 2010 Share Posted December 3, 2010 (edited) That internal __GuiCtrlListView_Sort() function is being called over and over again to compare item 0 to itself. It always matches, so no sorting changes are ever called for. With five items in the control, it gets called five times with both $nItem1 = 0 and $nItem2 = 0; so it returns 0 every time. Some'tn done be brok'ded! Edited December 3, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
BrewManNH Posted December 4, 2010 Share Posted December 4, 2010 It seems like that error only happens if you use the UDF functions to add the items to the LV. It's an odd occurence because you would think that the way the items are added to the LV shouldn't affect whether or not it gets sorted, unless there's some kind of weirdness dealing with handles vs controlids. I've tried adding items to the LV with the handle to the LV and using the ControlID, no difference. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
rover Posted December 4, 2010 Share Posted December 4, 2010 (edited) Greetings PsaltyDS and Ghost21 there are two issues the guictrlgethandle() call for the listview is missing, so $hLV is set to control ID replace this line in _Fill() _GUICtrlListView_AddItem($hLV, $aSplit[1]) with _GUICtrlListView_AddItem($cLV, $aSplit[1], -1, _GUICtrlListView_GetItemCount($cLV) + 9999) <these comments are relevant as of AU3 version 3.3.6.1> the help file remarks for _GUICtrlListView_RegisterSortCallBack omit to mention that you have to add the current item count and 9999 to the items LVITEM struct Param element when creating items for sorting to work, also the section in question in _AddRow() is off the right side of the screen in SciTE, unless you scroll to see it. I had read about this before I used sorting for the first time, so I was saved this grief, but not spared from others... another issue or trap like this is the lack of documentation on using extended styles in GUICtrlCreateListView. there should be a mention of _GUICtrlListView_SetExtendedListViewStyle for setting the third style type: LVS_EX and a caution not to BitOR extended windows styles with extended LVS_EX styles in the last param of GUICtrlCreateListView /<these comments are relevant as of AU3 version 3.3.6.1> @Ghost21 GUICtrlCreateListView uses control IDs up to 9999 in Param for internal use with GUICtrlCreateListViewItem this is why GUICtrlCreateListViewItem is not compatible with the UDFs see three examples below ** you can use GUICtrlCreateListView in practically all cases with the UDFs Siao had some comments on this about GUICtrlCreateListView and _GUICtrlListView_Create it is better to use the native Autoit listview advice on using UDFs with listview: use the LV control ID as much as possible with the UDFS your code is better optimized as you are mostly making native autoit calls to sendmessage (guictrlsendmsg) instead of dllcall sendmessage but, see the three exceptions listed below ** in SciTE, place cursor on udf name and Ctrl-J or open Tools menu "jump to function prod" this opens the listview include at the named function. see what happens if control id (Not IsHWnd($hWnd)) is used. you see the calls are directed to native GUICtrlSendMsg if control id supplied. however, this is not always the case with all UDFs, see the three exceptions below...** it is safer to use hwndfrom in WM_NOTIFY with the UDFS unless you intend to rewrite/optimize them for guictrlsendmsg you can use $IDFrom = DllStructGetData($tNMHDR, "IDFrom") for the control ID, but there are exceptions...** **_GUICtrlListView_SortItems is currently coded for a handle only, unlike many LV udfs that take both a handle and control ID **these two functions are special: use a handle for UDF added items  - use a control id for GUICtrlCreateListViewItem added items _GUICtrlListView_DeleteItem($hWnd, $iIndex) _GUICtrlListView_DeleteAllItems($hWnd) expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Global $aTestData[5] = ["PCname1|192.168.1.5|778993001|PC0|00112233FE", _ "PCname2|192.168.1.4|778993003|PC2|00112233BD", _ "PCname3|192.168.1.3|778993005|PC4|00112233AC", _ "PCname4|192.168.1.2|778993002|PC1|00112233F0", _ "PCname5|192.168.1.1|778993004|PC3|00112233E8"] Global $aColWidths[5] = [150, 110, 150, 300, 173] Global $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Global $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) Global $hGUI, $cLV, $hLV $hGUI = GUICreate("ListView Sort", 1004, 500) $cLV = GUICtrlCreateListView("Domain Device|IP Address|Serial Number|Description|Mac Address", 5, 100, 950, 237, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hLV, $iExListViewStyle) $hLV = GUICtrlGetHandle($cLV) For $n = 0 To UBound($aColWidths) - 1 _GUICtrlListView_SetColumnWidth($cLV, $n, $aColWidths[$n]) Next _GUICtrlListView_SetBkColor($cLV, 0xA6CAF0) _GUICtrlListView_JustifyColumn($cLV, 4, 2) _Fill() _GUICtrlListView_RegisterSortCallBack($hLV, True, True);should be passed handle to eliminate redundant conversion to handle in UDF GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($hLV);should be passed handle to eliminate redundant conversion to handle in UDF GUIDelete() Func _Fill() Local $aSplit For $n = 0 To UBound($aTestData) - 1 ; GUICtrlCreateListViewItem($aTestData[$n], $ListView) $aSplit = StringSplit($aTestData[$n], "|") ;_GUICtrlListView_AddItem($hLV, $aSplit[1]) _GUICtrlListView_AddItem($cLV, $aSplit[1], -1, _GUICtrlListView_GetItemCount($cLV) + 9999) For $s = 2 To $aSplit[0] _GUICtrlListView_AddSubItem($cLV, $n, $aSplit[$s], $s - 1) Next Next EndFunc ;==>_Fill Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") ;Local $IDFrom = DllStructGetData($tNMHDR, "IDFrom") Switch $hWndFrom Case $hLV Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) Local $iCol = DllStructGetData($tInfo, "SubItem") _GUICtrlListView_SortItems($hWndFrom, $iCol) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Edited December 4, 2010 by rover I see fascists... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now