Sign in to follow this  
Followers 0
Massi

Listview Problem. _GUICtrlListView_BeginUpdate - _GUICtrlListView_EndUpdate

8 posts in this topic

#1 ·  Posted (edited)

Hi all. I have a problem with Listview function.

I recently update from Autoit version 3.3.8.1 to new one. After the update the functions _GUICtrlListView_BeginUpdate - _GUICtrlListView_EndUpdate doesn't work in the right way. Listview doesn't wait _GUICtrlListView_EndUpdate to start updating so all the process is very slow.

I try to search what's wrong but I can't manage to make it work.

This is a piece of the code working, just to re-create the problem

#include-once
#include <EditConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>


Local $nMeta=550,$nAltezzaRiga=30,$nHMeta=300,$nLarghezzaLabel=70 ;PRIMA ERA 270 $Hmeta=$AltezzaRiga*9
Local $LarghezzaFinestra=1100,$AltezzaFinestra=700,$Font="Arial"

$hFinestra = GUICreate("TEST", $LarghezzaFinestra,$AltezzaFinestra) ; Crea una finestra larga 800 e alta 600
GUISetState(@SW_SHOW,$hFinestra)
    GUISetFont(10, 400, 0, "Comic Sans MS")
$lv = GUICtrlCreateListView("", 2, 2, $LarghezzaFinestra-4, 356);,$LVS_SORTDESCENDING)
$hLV = GUICtrlGetHandle($lv)
_GUICtrlListView_SetExtendedListViewStyle($hLV, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_AddColumn($hLV, "", 1500)
$BottoneRicerca = GUICtrlCreateButton("TEST", 250 ,380+ $nAltezzaRiga*5-3, 55, 30);30+$nLarghezzaLabel+220 + 400

local $aRisultatoTotale[100][50]
 For $x=0 To 99
    for $y=0 To 49
        $aRisultatoTotale[$x][$y]="AAAAAAAAAAAA"
    Next
 Next
Local $aNomeTabellaDatabase[3]=["2","TEST1","TEST2"]
 Local $aNumeroColonneTabella[3]=["2","10","15"]
Local   $aNumeroRigheTabella[3]=["2","3","6"]

    While 1
    $msg=GUIGetMsg()
        Select
            Case $msg=$BottoneRicerca
                GuiRicerca($hFinestra,$lv,$hLV,$aRisultatoTotale, $aNomeTabellaDatabase, $aNumeroColonneTabella, $aNumeroRigheTabella)
        Case $msg=$GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    WEnd
    GUIDelete($hFinestra)

Func GuiRicerca($hFinestra,$lv,$hLV,$aRisultatoTotale, ByRef $aNomeTabellaDatabase, ByRef $aNumeroColonneTabella, ByRef $aNumeroRigheTabella)
    Local $LarghezzaFinestra=1100,$AltezzaFinestra=700,$Font="Arial"

    Local $hDC = _WinAPI_GetDC($hLV)
    Local $hFont = _SendMessage($hLV, $WM_GETFONT)
    Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
    Local $lvLOGFONT = DllStructCreate($tagLOGFONT)
    Local $aRet = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize($lvLOGFONT), 'ptr', DllStructGetPtr($lvLOGFONT))
    _WinAPI_SelectObject($hDC, $hObject)
    _WinAPI_ReleaseDC($hLV, $hDC)
    DllStructSetData( $lvLOGFONT, "Height",15)
    $hLVfont = _WinAPI_CreateFontIndirect( $lvLOGFONT )
    DllStructSetData( $lvLOGFONT, "Weight", 700 )
    $hLVfontBold = _WinAPI_CreateFontIndirect( $lvLOGFONT )
    DllStructSetData( $lvLOGFONT, "Italic", True ) ;0 for normal, 1 for italic
    $hLVfontBoldItalic = _WinAPI_CreateFontIndirect( $lvLOGFONT )
    DllStructSetData( $lvLOGFONT, "Weight", 400 ) ;700 for bold, 400 for regular
    $hLVfontItalic = _WinAPI_CreateFontIndirect( $lvLOGFONT )

_GUICtrlListView_BeginUpdate($hLV) ; *************************************BEGIN of LISTVIEW UPDATE
    While _GUICtrlListView_DeleteColumn($hLV, 1)=True ;Delete all the columns
    WEnd
    _GUICtrlListView_DeleteAllItems($hLV) ; Delete all item from ListView
    For $x=1 to UBound($aRisultatoTotale,2)-1 ; Add columns (in this example the number of columns doesn't change)
        _GUICtrlListView_AddColumn($hLV, "", 100)
    Next
    $stringa=""
    For $x=0 To UBound($aRisultatoTotale,1)-1
        _GUICtrlListView_AddItem( $hLV,$aRisultatoTotale[$x][0])
        For $y=1 to  UBound($aRisultatoTotale,2)-1
            _GUICtrlListView_AddSubItem( $hLV,$x,$aRisultatoTotale[$x][$y],$y)
        Next
    Next

    For $x=0 to UBound($aRisultatoTotale,2)-1
        _GUICtrlListView_SetColumnWidth($lv, $x, $LVSCW_AUTOSIZE) ; Autofit the columns
    Next

_GUICtrlListView_EndUpdate($hLV) ; *************************************END of LISTVIEW UPDATE

EndFunc
Edited by Melba23
Amended thread title

Share this post


Link to post
Share on other sites



Massi,

When I run your code in both 3.3.12.0 and 3.3.13.19 the ListView update occurs only when the _GUICtrlListView_EndUpdate function is called and is extremely fast. Commenting the _GUICtrlListView_Start/EndUpdate lines results in the very slow update that would be expected. So I do not believe the problem is AutoIt-based - I have amended the thread title accordingly. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Sorry Melba, yes I see the function _GUICtrlListView_EndUpdate is fast but here listview begins updating before _GUICtrlListView_EndUpdate function is called. The first time you push TEST all works well.

Please, try to push the test button more than once. 

If you see autofit columns start before _GUICtrlListView_EndUpdate(maibe is diffcult to see because all the word are equal "AAAA"). If you put _GUICtrlListView_AddColumn($hLV, "", 50) instead of 100 this result is more clear

As I said in version  3.3.8.1 this doesn't happen but maybe is a script problem or a PC problem, in this case please accept my apologies

Share this post


Link to post
Share on other sites

Massi,

I see what you mean - the second time you do get the slow update. I believe this is because you are deleting all the columns and then adding new ones without allowing the control to realise what is happening. If I give the ListView a chance to update between these two sections it no longer shows the slow update:

_GUICtrlListView_BeginUpdate($hLV) ; ***********************************BEGIN of LISTVIEW UPDATE

While _GUICtrlListView_DeleteColumn($hLV, 1) = True
WEnd
_GUICtrlListView_DeleteAllItems($hLV) ; Delete all item from ListView

_GUICtrlListView_EndUpdate($hLV) ; *************************************END of LISTVIEW UPDATE

; Allow the ListView to update

_GUICtrlListView_BeginUpdate($hLV) ; ***********************************BEGIN of LISTVIEW UPDATE

; Updating code

_GUICtrlListView_EndUpdate($hLV) ; *************************************END of LISTVIEW UPDATE
Does that work for you? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Melba, N1

I also try to put other _GUICtrlListView_BeginUpdate($hLV) and _GUICtrlListView_EndUpdate($hLV) in other points of the script for debugging and was not working,

I see that the GuiListView.au3 is changed in the two versions but was very complicated to understand the differences.

I think that the right way to work was the previous one or the function doesn't do "Prevents updating of the control until the _GUICtrlListView_EndUpdate() function is called".

Make a lot of operations in listview should not modify the behaviour of the function.This behaviour have to be documented or in my opinion this is a little bug.

In everycase this workaround work for me, thank you Melba :thumbsup:

Edited by Melba23
Resized font

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Massi,

I have just checked the _GUIListView libraries in 3.3.8.1 and 3.3.12.0 and I have found the reason you see this change in behaviour. :)

The _GUICtrlListView_DeleteAllItems in v3.3.8.1 did not actually work, so I rewrote it. If the ListView is created by the native GUICtrlCreateListView function deleting all the items takes some time, so I added an internal version of the Begin/EndUpdate function. Thus in your script, calling that function means that the ListView is updated as it exits and so you need to reset the StartUpdate state before you start refilling. ;)

I will add a remark to the _GUICtrlListView_DeleteAllItems page in the Help file explaining this - thanks for noticing it! :thumbsup:

M23

Edit: Remark added. :)

Edited by Melba23
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thank you Melba, now is all clear and working.

If I put _GUICtrlListView_BeginUpdate after _GUICtrlListView_DeleteAllItems all work fine(there is no need of _GUICtrlListView_EndUpdate because the function already do this).

Is exactly as you say (I try other scripts with _GUICtrlListView_BeginUpdate but I cannot replicate the problem because it was in another function :sweating: )

Thank you very much for helping me :thumbsup:  :bye:

Share this post


Link to post
Share on other sites

Massi,

My pleasure (particularly as it was my fault!). :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0