crystalburner Posted May 11, 2007 Share Posted May 11, 2007 Hi! Had this annoying prob for a long while now.... $invoicelist = GUICtrlCreateListView ("Invoice # |Date |Firstname |Surname |Company |Building |Address1 |Address2 |Postcode |Database ref#",0,0,600,350,bitor($LVS_SORTDESCENDING,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT,$LVS_SINGLESEL)) When I add invoices to the list, they are sorted, like so 999 998 997 996 Great! But since I hit invoice 1000 I get this 999 998 997 996 1004 1003 1002 1001 I can see what its doing but the only way I have found so far around this problem is to add all the invoice to an array first, sort the array then add them to the list, but the trouble is they get added to the list ad - hoc (the list updates in real time) and so the new ones that get added then arent sorted properly Any ideas? Link to comment Share on other sites More sharing options...
crystalburner Posted May 11, 2007 Author Share Posted May 11, 2007 By the way, I call this function with this command to keep the list sorted when new items are added. This is the prob I think but not sure where to fix it GUICtrlRegisterListViewSort(-1, "LVSort") Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * -1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($lvname, $nItem1, $nColumn) $val2 = GetSubItemText($lvname, $nItem2, $nColumn) ; If it is the 3rd colum (column starts with 0) then compare the dates If $nColumn = 2 Then $val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2) $val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2) EndIf $nResult = 0 ; No change of item1 and item2 positions If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 11, 2007 Share Posted May 11, 2007 Any ideas? Use StringFormat() to make them all the same number of digits with leading zeros: $n = "989" $n = StringFormat("%06u", $n) MsgBox(64, "Demo", "Like this: " & $n) 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...
crystalburner Posted May 11, 2007 Author Share Posted May 11, 2007 Use StringFormat() to make them all the same number of digits with leading zeros: $n = "989" $n = StringFormat("%06u", $n) MsgBox(64, "Demo", "Like this: " & $n) I didn't have any luck with that sadly and also the strings are like this 999 - DATE - INV NUM - CLIENT - REF.DOC Link to comment Share on other sites More sharing options...
crystalburner Posted May 11, 2007 Author Share Posted May 11, 2007 I didn't have any luck with that sadly and also the strings are like this999 - DATE - INV NUM - CLIENT - REF.DOC The guilist strips off the leading 0 as well !!! Link to comment Share on other sites More sharing options...
crystalburner Posted May 11, 2007 Author Share Posted May 11, 2007 What i really need if someone understands the code well enough is to fix the problem with the listsort function .... Can anyone help? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 11, 2007 Share Posted May 11, 2007 The guilist strips off the leading 0 as well !!! That should only happen if you are passing it an integer variable instead of a string. The following two variables should be treated differently: $Var1 = 000989 $Var2 = "000989"oÝ÷ Ù8^JÚâh®f².ÖÞ+⨹«-®)àZ)íz«nër¢ç(ºWfjG¬º·°Øl¢g)à)¶¬jëh×6#include <date.au3> $n = "989" $Date = _Now() $InvNum = "123123" $Cust = "Widgets Inc." $RefDoc = "Purchase Order AB12CD34" $Entry = StringFormat("%06u - %s - %012u - %s - %s", $n, $Date, $InvNum, $Cust, $RefDoc) MsgBox(64, "Demo", "Like this: " & $Entry) 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...
crystalburner Posted May 11, 2007 Author Share Posted May 11, 2007 Ok. first, thank you! Second, I can use some of this to fix this problem!!!! I have new problems tho but I can deal with them. Thanks Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 11, 2007 Share Posted May 11, 2007 You're welcome. 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...
randallc Posted May 11, 2007 Share Posted May 11, 2007 Hi, alternatuively, modify the Sort as you said originally; Func LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort If $nColumn = $nCurCol Then; Switch the sorting direction If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($lv, $nItem1, $nColumn) $val2 = GetSubItemText($lv, $nItem2, $nColumn) If (StringIsFloat($val1) Or StringIsInt($val1)) And (StringIsFloat($val2) Or StringIsInt($val2)) Then Return _Iif(Number($val1) < Number($val2), -1, _Iif(Number($val1) > Number($val2), 1, 0)) * $nSortDir Return _Iif($val1 < $val2, -1, _Iif($val1 > $val2, 1, 0)) * $nSortDir EndFunc ;==>LVSortBest, Randall [Add back the date part too if needed for a specific column...] ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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