Jump to content

_GUICtrlListView_AddArray()


disc330
 Share

Recommended Posts

I'm using _GUICtrlListView_AddArray() along with an SQL query to read records and put them into a list but its taking way too long.

I'm currently only using 3 records, and its taking about 7 seconds to just perform the _GUICtrlListView_AddArray() function.

If anyone knows a faster way, or knows what im doing wrong here please do tell. ( I assume I am doing something VERY wrong because the helpfile example takes just over a second to display 5000 records with 4 columns...)

Code:

While _SQLite_FetchData ($hQuery, $aRows) = $SQLITE_OK 
    $RowColCount = StringSplit(_ArrayToString($aRows,"|"),"|")
    For $ii = 0 to $RowColCount[0]-1
        $aItems[$i][$ii] = $aRows[$ii]
    Next
    $i += 1
WEnd
$timer = TimerInit()
_GUICtrlListView_AddArray($LTV_SQLTableData,$aItems)
MsgBox(0,"",TimerDiff($timer) )

Still learning...I love autoit. :)

Link to comment
Share on other sites

Link to comment
Share on other sites

Mmm..yes. I like the way you think. Ill go try it. thanks :)

EDIT: After testing...

Without the line: 7.6 Seconds

With the line: 7.4 Seconds... o.O

Still far from ideal. I dont understand what it is. Would it help to use the:

_GUICtrlListView_BeginUpdate($hListView)

_GUICtrlListView_EndUpdate($hListView)

functions? I will go try that now actually. Thanks for the help though still.

EDIT 2:

Nope, still taking way to long. probably because its al done in one update anyway.

However, I just noticed that if I keep refreshing the rows, the time it takes to fill the data increases...

Also the scroll bar shows that the list is suddenly huge and filled with far too much empty space.

Solved: I was looking in the wrong place.

Dim $aItems[50000][20] <--- it was showing all the rows empty or not. :)

Edited by disc330

Still learning...I love autoit. :)

Link to comment
Share on other sites

Solved: I was looking in the wrong place.

Dim $aItems[50000][20] <--- it was showing all the rows empty or not. :)

^_^, that's why it took 7 seconds...

Threw together a dynamic example (dirty :)) from the help-file, how to dynamically determine the columns and records. Could definitely do some more error checking, but it works under the given circumstances and might be a good start point (only appoint as much memory to the array as needed).

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include<WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

Global $iTimer, $hListView, $aItems, $itemcount
Global $hQuery, $aRow
Global $aNames[1], $aRow[1], $aItems[1][1]

; Create GUI
GUICreate("ListView Add Array", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_STATICEDGE, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
$hListView = GUICtrlGetHandle($hListView)
_GUICtrlListView_SetUnicodeFormat($hListView, False)

_SQLite_Startup()
_SQLite_Open(); open :memory: Database
_SQLite_Exec(-1, "CREATE TABLE aTest (col_a,col_b,col_c);")

For $i = 1 To 5000
    _SQLite_Exec(-1, "INSERT INTO aTest(col_a,col_b,col_c) VALUES (" & $i & "," & $i+1 & ","& $i+2 &");")
Next

GUISetState()

_SQLite_Query(-1, "SELECT count(*) FROM aTest;", $hQuery)
If _SQLite_FetchData($hQuery, $aRow) <> $SQLITE_OK Then
    MsgBox(270400, '', "No records were found in the result set...")
    ReDim $aRow[1]
    $aRow[0] = 0
EndIf
_SQLite_QueryFinalize($hQuery)

If $aRow[0] > 0 Then
    
    _SQLite_Query(-1, "SELECT * FROM aTest LIMIT 1;", $hQuery)
    _SQLite_FetchNames($hQuery, $aNames); Read out Column Names
    _SQLite_QueryFinalize($hQuery)

    For $i = 1 To UBound($aNames)
        _GUICtrlListView_AddColumn($hListView, $aNames[$i-1], 100)
    Next

    $itemcount = $aRow[0]
    ReDim $aItems[$itemcount][UBound($aNames)]

    $i = 0
    _SQLite_Query(-1, "SELECT * FROM aTest;", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        For $y = 0 To UBound($aNames) - 1
            $aItems[$i][$y] = $aRow[$y]
        Next
        $i += 1
    WEnd
    _SQLite_QueryFinalize($hQuery)

    _GUICtrlListView_SetItemCount($hListView, UBound($aItems) - 1)
    $iTimer = TimerInit()
    _GUICtrlListView_AddArray($hListView, $aItems)
    MsgBox(4160, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds")
EndIf

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete()
_SQLite_Close()
_SQLite_Shutdown()
Edited by KaFu
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...