Jump to content

Listview flicker when in tab item


Go to solution Solved by Kilmatead,

Recommended Posts

Posted

My script needs to load data from external source to listview control, sometimes over 1000 items.

I have a need to have more than one listview control loaded with data, so decided to add a couple of tabs.

Without listview in tabitem, it loads within around 500ms, but when it is in tab item it takes 10x that and flickers like crazy.

Anyone know of a workaround?

Below is my reproducer code, test it without tab item, then uncomment Tab 1 to see problem.

#include <ListViewConstants.au3>
#include <GuiListView.au3>

$sLVI = "one|two|three|four"

$Gui = GUICreate("GUI", 600, 600, 100, 100)

$button = GUICtrlCreateButton("go", 560, 20)

GUICtrlCreateTab(0, 0, 500, 500)
;GUICtrlCreateTabItem("Tab 1")

$hLV = GUICtrlCreateListView($sLVI, 0, 20, 500, 500)
_GUICtrlListView_SetExtendedListViewStyle($hLV, BitOR($LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))

GUICtrlCreateTabItem("Tab 2")

GUISetState()
While 3
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $button
            PopulateLV()
    EndSwitch
WEnd

Func PopulateLV()
    For $i = 0 To 300
        GUICtrlCreateListViewItem($sLVI, $hLV)
    Next
EndFunc   ;==>PopulateLV

Disabling the listview control has no effect, nor does hiding it.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted (edited)
  On 2/22/2015 at 11:30 PM, JohnOne said:

Anyone know of a workaround?

 

avoid repaint

switch to tab 2

fill listview

switch to tab 1

repaint

:)

edit: typo

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Only workaround I can figure is to hide the whole gui, which is a bit overkill I think.

Func PopulateLV()
    GUISetState(@SW_HIDE)
    For $i = 0 To 300
        GUICtrlCreateListViewItem($sLVI, $hLV)
    Next
    GUISetState(@SW_SHOW)
EndFunc   ;==>PopulateLV

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted
  On 2/22/2015 at 11:45 PM, JohnOne said:

Makes no difference bud, still flicker.

 

Time for Func PopulateLV  is much better.

#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>


$sLVI = "one|two|three|four"

Global $hGUI = GUICreate("GUI", 600, 600, 100, 100)

$button = GUICtrlCreateButton("go", 560, 20)

GUICtrlCreateTab(0, 0, 500, 500)
GUICtrlCreateTabItem("Tab 1")
Global $hLV = GUICtrlCreateListView($sLVI, 0, 20, 500, 500)
_GUICtrlListView_SetExtendedListViewStyle($hLV, BitOR($LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")
GUISetState()


While 3
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $button
            PopulateLV(False)
            PopulateLV(True)
    EndSwitch
WEnd

Func PopulateLV($bTest)
    Local $hTimer = TimerInit()
;~  If $bTest Then _WinAPI_RedrawWindow ( $hGUI,0,0,BitOR($RDW_NOINTERNALPAINT,$RDW_NOERASE , $RDW_NOFRAME ) )
    If $bTest Then _GUICtrlListView_BeginUpdate ( $hLV)
    For $i = 0 To 300
        GUICtrlCreateListViewItem($sLVI, $hLV)
    Next
    Local $iDiff = TimerDiff($hTimer)
    If $bTest Then _GUICtrlListView_EndUpdate( $hLV)
;~  If $bTest Then _WinAPI_RedrawWindow ( $hGUI,0,0,$RDW_INTERNALPAINT )
    MsgBox(0, "Time Difference", $iDiff/1000)

EndFunc   ;==>PopulateLV

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Combined with mLipok sugestion, which on it's own still produces flicker, it is even quicker.

Thank you both.

Func PopulateLV()
    _GUICtrlListView_BeginUpdate ($hLV)
    _WinAPI_LockWindowUpdate($hGUI)

    For $i = 0 To 1000
        GUICtrlCreateListViewItem($sLVI, $hLV)
    Next

    _WinAPI_LockWindowUpdate(Null)
    _GUICtrlListView_EndUpdate( $hLV)
    _WinAPI_InvalidateRect($hGUI)
    _WinAPI_UpdateWindow($hGUI)
EndFunc   ;==>PopulateLV

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

take a look:

#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <GuiTab.au3>

$sLVI = "one|two|three|four"

Global $Gui = GUICreate("GUI", 600, 600, 100, 100)

$button = GUICtrlCreateButton("go", 560, 20)

Global $hTab = GUICtrlCreateTab(0, 0, 500, 500)
Global $idTab1 = GUICtrlCreateTabItem("Tab 1")
Global $hLV = GUICtrlCreateListView($sLVI, 0, 20, 500, 500)
_GUICtrlListView_SetExtendedListViewStyle($hLV, BitOR($LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
Global $idTab2 = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")
GUISetState()


While 3
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $button
            PopulateLV()
    EndSwitch
WEnd

Func PopulateLV()
    Local $hTimer = TimerInit()
    _WinAPI_LockWindowUpdate($Gui)
    _GUICtrlTab_ClickTab($hTab, 1)
    For $i = 0 To 300
        GUICtrlCreateListViewItem($sLVI, $hLV)
    Next
    _GUICtrlTab_ClickTab($hTab, 0)
    _WinAPI_LockWindowUpdate(0)
;~  _WinAPI_InvalidateRect($Gui)
;~  _WinAPI_UpdateWindow($Gui)
    MsgBox(0, "Time Difference", TimerDiff($hTimer) / 1000)
EndFunc   ;==>PopulateLV

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

That makes it quicker indeed, mLipok.

Good thinking.

For me though, I may have many tabs, and keeping track of which is active may not outweigh the benefits of the speed.

Thanks again.

EDIT:

Also, when script first starts, there may only be one tab, until another is added.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

I am interested in explaining why these two functions:

;~  _WinAPI_InvalidateRect($Gui)
;~  _WinAPI_UpdateWindow($Gui)

have been used, although as you can see they are not needed.

Does anyone have any ideas?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

J1,

No flicker and 1000 loaded in .05 sec...

#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <GuiTab.au3>

$sLVI = "one|two|three|four"

Global $Gui = GUICreate("GUI", 600, 600, 100, 100)

$button = GUICtrlCreateButton("go", 560, 20)

Global $hTab = GUICtrlCreateTab(0, 0, 500, 500)
Global $idTab1 = GUICtrlCreateTabItem("Tab 1")
Global $hLV = GUICtrlCreateListView($sLVI, 0, 20, 500, 500)
_GUICtrlListView_SetExtendedListViewStyle($hLV, BitOR($LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
Global $idTab2 = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("")
GUISetState()


While 3
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $button
            PopulateLV()
    EndSwitch
WEnd

Func PopulateLV()
    Local $hTimer = TimerInit()
    GUISetState(@SW_LOCK)
    For $i = 0 To 1000
        GUICtrlCreateListViewItem($sLVI, $hLV)
    Next
    GUISetState(@SW_UNLOCK)
    _GUICtrlTab_ClickTab($hTab, 0)
    MsgBox(0, "Time Difference", TimerDiff($hTimer) / 1000)
EndFunc   ;==>PopulateLV

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

and Dreams Come to True :)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@J1

I made some tests.

With Clicikng tab is slower then without clicking.

@kylomas can you edit your script, so for posterity :)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  Quote

Not sure how the clicking tab is needed though.

 

It has no bearing on flicker or speed on populating the listview.  I thought it was part of what you were doing afterward.

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...