Jump to content

Recommended Posts

Posted

I'm currently populating a listview using a Do While loop and it takes around 10 seconds to populate the list.

Is there a better alternative?

Thanks

Func StartUp()
    Local $clicks = 0, $info
    _GUICtrlListViewSetColumnWidth ($listview, 0, 93)
    Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ]
    $num = 1
    Global $strMACAddress
    If FileExists($file) = 0 Then FileWrite($file, "")
    $msg = GUIGetMsg()
    Do
        $line = FileReadLine($file, $num)
        If $line <> "" Then GUICtrlCreateListViewItem($line, $listview)
        $num = $num + 1
        $percent = Round(($num / _FileCountLines($file))*100, 0)
        _GUICtrlStatusBarSetText($StatusBar, "Building list, " & $percent&"% complete")
        GUICtrlSetData($ProgressBar1, $percent)
    Until $line = ""
    _GUICtrlListViewSort($listview, $B_DESCENDING, 0)
    GUISetState(@SW_ENABLE, $main)
    GUICtrlSetState($input, $GUI_FOCUS)
    GUICtrlSetData($ProgressBar1, 0)
    SelectionTotal()
EndFunc
Posted

@buymeapc....I wouldnt use a do loop for this....try using the following...

_FileReadToArray($file,$File_Array)

For $x=1 to $File_Array[0]

;Create your listviewitems
;Update your progressbar

Next
Posted

If you mean sorting the listview results...then yes sure you can...just search the forum for listview and sort. There are many UDFs out there but I believe gafrost's udf is pretty fast....

Posted

Personally, I would use _FileReadToArray() to read the info in, then use _ArraySort(), then populate the listview. This would eliminate the need to use the ListView sort.

Posted

Hi,

1. I agree with WeaponX

2. Take "_FileCountLines" out of any loop as it reads the whole file each time (assign to var)

3. If only one column, consider "ListBox" instead of listview;

3a then you can do fileread without array, replace "@crlf" with "|" separator, add to LB in one command, no loop, and automatically sorts

4. I f you use LV and ArraySort is still slow, quickest sort on 1D array is via jscript and scripting object (10x)

Let me know..

Best, Randall

Posted

Oh wow, that is so much better!! I commented out the status bar lines and what a difference!

Thanks guys!....Here's the code I used:

Func StartUp()
    GUISetState(@SW_DISABLE, $main)
    Local $File_Array, $num = 1
    _GUICtrlListViewSetColumnWidth ($listview, 0, 93)
    Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ]
    If FileExists($file) = 0 Then FileWrite($file, "")
    _FileReadToArray($file, $File_Array)
    _ArraySort($File_Array, 0, 1)
    $msg = GUIGetMsg()
    For $x = 1 To $File_Array[0]
        If $File_Array[$x] <> "" Then GUICtrlCreateListViewItem($File_Array[$x], $listview)
    ;$num = $num + 1
    ;$percent = Round(($num / _FileCountLines($file))*100, 0)
    ;_GUICtrlStatusBarSetText($StatusBar, "Building list, " & $percent&"% complete")
    ;GUICtrlSetData($ProgressBar1, $percent)
    Next
;_GUICtrlListViewSort($listview, $B_DESCENDING, 0)
    GUISetState(@SW_ENABLE, $main)
    GUICtrlSetState($input, $GUI_FOCUS)
;GUICtrlSetData($ProgressBar1, 0)
    SelectionTotal()
    GUISetState(@SW_ENABLE, $main)
EndFunc

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
×
×
  • Create New...