Jump to content

Creation of ListView Items takes a lot of time...


Recommended Posts

Good evening everyone :)
I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
It is normal that it takes so much time?
What can I do to improve the creation of the items?

Here's the code I am using to query and to create ListView items...

; Articles ListView:
Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))

; Query
$strQuery = "SELECT * FROM ARTICOLI;"

; Query Execution
_SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns)
If @error Then
    ; Error Handling
Else
    ; Cleaning the ListView
    _GUICtrlListView_DeleteAllItems($lvwArticles)
    If @error Then
        ; Error Handling
    Else
        ; No records in the Table
        If UBound($arrResult) < 2 Then
            ; Error Handling
        Else
            _GUICtrlListView_BeginUpdate($lvwArticles)

            For $intCounter = 1 To UBound($arrResult) - 1

                $strListViewItem = $arrResult[$intCounter][0] & "|" & _
                                   $arrResult[$intCounter][1] & "|" & _
                                   $arrResult[$intCounter][2] & "|" & _
                                   $arrResult[$intCounter][3] & "|" & _
                                   $arrResult[$intCounter][4] & "|" & _
                                   $arrResult[$intCounter][5] & "|" & _
                                   $arrResult[$intCounter][6] & "|" & _
                                   $arrResult[$intCounter][7]

                $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles)
            Next

            _GUICtrlListView_EndUpdate($lvwArticles)

        EndIf
    EndIf
EndIf

Thanks in advance :)


Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@AutoBert

I didn't watch closely in the Help file!

Didn't know about that function :)

I will try that tomorrow, and I'll let you know :)

Thanks for the suggestion.

PS: How could I measure the time since I start to create ListView Items and when the last ListView Item is displayed? 

Just for curiosity :)

Thanks again!

 

Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

To get an idea of how fast you can insert the rows in a listview, try displaying the array with _ArrayDisplay(). The code in _ArrayDisplay() is optimized code and It can probably not be done faster.

If it's not fast enough, then there is an ultimate solution. This solution consists of using a virtual listview. In a virtual listview, data is not inserted in the listview. Instead, the virtual listview reads data directly from the source. In this case either the array or the SQLite database.

Virtual listviews are fully and completely supported by AutoIt code.

To get an idea of how fast you can show the array in a virtual listview, try displaying the array with _ArrayDisplayEx().

There is also a function _SQLite_Display() that can display data from a SQLite database directly in a virtual listview. This function is very very fast. The total time spent reading the 29,000 rows from the database and displaying the first page in the listview will probably be less than one second.

Use this example to create your own virtual listview.

Link to comment
Share on other sites

@AutoBert Thanks for your suggestions :) I will check them tomorrow in the morning.

@LarsJ Wow! Didn't know anything about that... :) Let me take a look and bring you a feedback :)

Another little question ( for me you are like Masters in this programming language ): I'd like to improve my knowledge about AutoIt... Where can I take a look? 

Thanks! 

 

Best Regards.

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@AutoBert
Now it takes about 19 seconds to "fill" the ListView, but the "bug" is, that the ListView is not filled correctly, because, in the ListView, it is displayed only the first and the last element of the array.
I don't know why...


I'm going to see what kind of things are Virtual ListViews :)


Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

And you remembered to check the input parameters for _GUICtrlListView_AddArray() in the help file?

Another little answer: You can take a look in the Microsoft documentation.

Link to comment
Share on other sites

27 minutes ago, LarsJ said:

And you remembered to check the input parameters for _GUICtrlListView_AddArray() in the help file?

Sure :)

Isn't a Result array from _SQLite_GetTable2() already formatted in that way ( as _GUICtrlListView_ArrayAdd requests )? :)

The Help file is my Guide :D

 

Best Regards.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Yes, It's just a normal 2D array. And _GUICtrlListView_AddArray() is pretty simple code. And therefore it should work. And when simpel code isn't working, it should not be ignored. You have to investigate the problem.

Link to comment
Share on other sites

@LarsJ

I'll do some screenshot in order to let you see what is the issue I reported to AutoBert.

I didn't investigate on this, but If I use _SQLite_Display2DResult() or _ArrayDisplay, it works correctly.

Today, I spent my time studying on how Virtual ListView controls work, but, there were a lot information provided by your code, and not so much experience about that by my side.

So, I had to start from a previous step, or:

Since Virtual ListViews are created capturing WM_NOTIFY Windows Message, I had/have to understand how all Notification Codes and Structs and so on work.

So, I was asking where I can find those information.

I am 22 yo, with a big willingness to learn...

Every suggest is really appreciated.

Thanks again for your help :)

 

Best Regards.

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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

×
×
  • Create New...