Jump to content
topten

_Guictrllistview UPDATE

Recommended Posts

topten

Hi Everyone

I am trying to figure out is there any more nice way to update an item in _guictrllistview

At the present I am using

_GUICtrlListView_DeleteAllItems($hListView)
 _GUICtrlListView_InsertItem($hListView, $Fetch_data[0], 0)
 _GUICtrlListView_AddSubItem($hListView,0, $Fetch_data[2], 1,1)
_GUICtrlListView_AddSubItem($hListView, 0, $Fetch_data[3], 2, 2)
_GUICtrlListView_AddSubItem($hListView, 0,  $Fetch_data[1], 3, 3)
_GUICtrlListView_AddSubItem($hListView, 0,  $Fetch_data[4], 4, 4)
_GUICtrlListView_AddSubItem($hListView, 0,  $Fetch_data[5], 5, 5)

And it works ok if you have 10-20 rows. But if you have 1000 rows and the data is dynamically updated- you'll have to wait long time when it is rebuilt :)

 

Share this post


Link to post
Share on other sites
reb

If the items exist then  why not use _GUICtrlListView_SetItem  ?


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites
topten

The items are fetched in a loop from array... Anyway, thanx for a clue, I will try using it

Share this post


Link to post
Share on other sites
LarsJ

To update a list view in a fast way use code as you see in the FillListView function in bottom of this example.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
;#include "Cursor.au3"

Opt( "MustDeclareVars", 1 )

Global $hGui

Example()


Func Example()
  ; Create GUI
  $hGui = GUICreate( "GUICtrlCreateListViewItem ListViews", 850, 400 )

  ; Create Tab
  Local $idTab = GUICtrlCreateTab( 10, 10, 850-20, 400-20 )
  GUICtrlCreateTabItem( "Array: 10,000 rows" )
  GUICtrlCreateTabItem( "Array: 20,000 rows" )
  GUICtrlCreateTabItem( "Array: 30,000 rows" )
  GUICtrlCreateTabItem( "Array: 40,000 rows" )
  GUICtrlCreateTabItem( "Array: 50,000 rows" )
  GUICtrlCreateTabItem( "" )

  ; Create ListView
  Local $idLV = GUICtrlCreateListView( "", 20, 40, 850-40, 400-60, $GUI_SS_DEFAULT_LISTVIEW, BitOR( $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES ) )
  Local $hLV = GUICtrlGetHandle( $idLV ) ;                                                                             Reduces flicker                              Checkboxes
  For $i = 0 To 9
    _GUICtrlListView_AddColumn( $hLV, "Col" & $i, 75 )
  Next

  ; Load icon images
  Local $hImage = _GUIImageList_Create()
  _GUIImageList_Add( $hImage, _GUICtrlListView_CreateSolidBitMap( $hLV, 0xFF0000, 16, 16 ) ) ; Index = 0
  _GUIImageList_Add( $hImage, _GUICtrlListView_CreateSolidBitMap( $hLV, 0x00FF00, 16, 16 ) ) ; Index = 1
  _GUIImageList_Add( $hImage, _GUICtrlListView_CreateSolidBitMap( $hLV, 0x0000FF, 16, 16 ) ) ; Index = 2
  _GUICtrlListView_SetImageList( $hLV, $hImage, 1 )

  GUISetState( @SW_SHOW )

  ; Data
  Local $iRows, $iRows1 = 0, $iRows2 = 0, $iRows3 = 0, $iRows4 = 0, $iRows5 = 0
  Local $aItems, $aItems1[10000][10], $aItems2[20000][10], $aItems3[30000][10], $aItems4[40000][10], $aItems5[50000][10]

  ; Data for first tab
  $iRows1 = FillArray( $aItems1, 10000 )
  $iRows = $iRows1
  $aItems = $aItems1
  FillListView( $idLV, $aItems, $iRows )

  ; Message loop
  While 1
    Switch GUIGetMsg()
      Case $idTab
        ;HourglassCursor( True )
        WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews. Delete all items" )
        _GUICtrlListView_DeleteAllItems( $hLV )
        ;HourglassCursor( False )
        Switch GUICtrlRead( $idTab )
          Case 0
            If $iRows1 = 0 Then _
              $iRows1 = FillArray( $aItems1, 10000 )
            $iRows = $iRows1
            $aItems = $aItems1
          Case 1
            If $iRows2 = 0 Then _
              $iRows2 = FillArray( $aItems2, 20000 )
            $iRows = $iRows2
            $aItems = $aItems2
          Case 2
            If $iRows3 = 0 Then _
              $iRows3 = FillArray( $aItems3, 30000 )
            $iRows = $iRows3
            $aItems = $aItems3
          Case 3
            If $iRows4 = 0 Then _
              $iRows4 = FillArray( $aItems4, 40000 )
            $iRows = $iRows4
            $aItems = $aItems4
          Case 4
            If $iRows5 = 0 Then _
              $iRows5 = FillArray( $aItems5, 50000 )
            $iRows = $iRows5
            $aItems = $aItems5
        EndSwitch
        FillListView( $idLV, $aItems, $iRows )

      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
  GUIDelete()
EndFunc

Func FillArray( ByRef $aItems, $iRows )
  Local $k
  ;HourglassCursor( True )
  For $i = 0 To $iRows / 10000 - 1
    $k = $i * 10000
    For $j = 0 To 9999
      $aItems[$k+$j][0] = $k + $j
      For $l = 1 To 9
        $aItems[$k+$j][$l] = $k + $j & "/" & $l
      Next
    Next
    WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews. Fills array: " & $k + 10000 & " rows" )
  Next
  ;HourglassCursor( False )
  WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews" )
  Return $iRows
EndFunc

Func FillListView( $idLV, ByRef $aItems, $iRows )
  Local $tLVITEM = DllStructCreate( $tagLVITEM )
  Local $pLVITEM = DllStructGetPtr( $tLVITEM ), $k, $s
  DllStructSetData( $tLVITEM, "Mask", $LVIF_IMAGE ) ; Icon (or image)
  DllStructSetData( $tLVITEM, "SubItem", 0 )        ; First column
  ;HourglassCursor( True )
  For $i = 0 To $iRows / 10000 - 1
    $k = $i * 10000
    For $j = 0 To 9999
      ; Text
      $s = $aItems[$k+$j][0]
      For $l = 1 To 9
        $s &= "|" & $aItems[$k+$j][$l]
      Next
      GUICtrlCreateListViewItem( $s, $idLV )        ; Add item and all texts

      ; Icon
      Select
        Case Mod( $k + $j, 3 ) = 0
          DllStructSetData( $tLVITEM, "Image", 2 )  ; Icon index
        Case Mod( $k + $j, 2 ) = 0
          DllStructSetData( $tLVITEM, "Image", 1 )
        Case Else
          DllStructSetData( $tLVITEM, "Image", 0 )
      EndSelect
      DllStructSetData( $tLVITEM, "Item", $k + $j ) ; Row
      GUICtrlSendMsg( $idLV, $LVM_SETITEMW, 0, $pLVITEM ) ; Add icon
    Next
    WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews. Fills listview: " & $k + 10000 & " rows" )
  Next
  ;HourglassCursor( False )
  WinSetTitle( $hGui, "", "GUICtrlCreateListViewItem ListViews" )
EndFunc

Maybe this example does not match your situation too good. I'll add a better example tomorrow.

Edited by LarsJ
The last sentence

Share this post


Link to post
Share on other sites
guinness

Also look at begin update, to stop repainting on every addition.

 


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
LarsJ

Here is a better example:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>

Opt( "MustDeclareVars", 1 )

Global $hGui

Example()


Func Example()
  ; Create GUI
  $hGui = GUICreate( "ListView: 10,000 rows", 850, 440 )

  ; Create ListView
  Local $idLV = GUICtrlCreateListView( "", 10, 10, 850-20, 400-20, $GUI_SS_DEFAULT_LISTVIEW, BitOR( $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES ) )
  Local $hLV = GUICtrlGetHandle( $idLV ) ;                                                                             Reduces flicker                              Checkboxes
  For $i = 0 To 9
    _GUICtrlListView_AddColumn( $hLV, "Col" & $i, 75 )
  Next

  ; Create button
  Local $idBut = GUICtrlCreateButton( "Update 1000 rows", 10, 400, 200, 30 )

  ; Load icon images
  Local $hImage = _GUIImageList_Create()
  _GUIImageList_Add( $hImage, _GUICtrlListView_CreateSolidBitMap( $hLV, 0xFF0000, 16, 16 ) ) ; Index = 0
  _GUIImageList_Add( $hImage, _GUICtrlListView_CreateSolidBitMap( $hLV, 0x00FF00, 16, 16 ) ) ; Index = 1
  _GUIImageList_Add( $hImage, _GUICtrlListView_CreateSolidBitMap( $hLV, 0x0000FF, 16, 16 ) ) ; Index = 2
  _GUICtrlListView_SetImageList( $hLV, $hImage, 1 )

  GUISetState( @SW_SHOW )

  ; Fill array
  Local $iRows = 10000, $aItems[$iRows][10]
  FillArray( $aItems, $iRows )

  ; Fill ListView
  FillListView( $idLV, $aItems, $iRows )

  ; Get control ID for first item
  ; (Control ID is stored in ItemParam)
  Local $idLVItem0 = _GUICtrlListView_GetItemParam( $hLV, 0 )

  ; Message loop
  While 1
    Switch GUIGetMsg()
      Case $idBut
        UpdateListView( $idLVItem0, 1000 )
        MsgBox( 0, "UpdateListView", "Done" )
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
  GUIDelete()
EndFunc

Func FillArray( ByRef $aItems, $iRows )
  For $i = 0 To $iRows - 1
    For $j = 1 To 9
      $aItems[$i][$j] = $i & "/" & $j
    Next
  Next
EndFunc

Func FillListView( $idLV, ByRef $aItems, $iRows )
  Local $tLVITEM = DllStructCreate( $tagLVITEM )
  Local $pLVITEM = DllStructGetPtr( $tLVITEM ), $k, $s
  DllStructSetData( $tLVITEM, "Mask", $LVIF_IMAGE )     ; Icon (or image)
  DllStructSetData( $tLVITEM, "SubItem", 0 )            ; First column
  For $i = 0 To $iRows - 1
    ; Text
    $s = $aItems[$i][0]
    For $j = 1 To 9
      $s &= "|" & $aItems[$i][$j]
    Next
    GUICtrlCreateListViewItem( $s, $idLV )              ; Add item and all texts
    ; Icon
    Select
      Case Mod( $i, 3 ) = 0
        DllStructSetData( $tLVITEM, "Image", 2 )        ; Icon index
      Case Mod( $i, 2 ) = 0
        DllStructSetData( $tLVITEM, "Image", 1 )
      Case Else
        DllStructSetData( $tLVITEM, "Image", 0 )
    EndSelect
    DllStructSetData( $tLVITEM, "Item", $i )            ; Row
    GUICtrlSendMsg( $idLV, $LVM_SETITEMW, 0, $pLVITEM ) ; Add icon
  Next
EndFunc

Func UpdateListView( $idLVItem0, $iRows )
  Local $item, $text = "|Updated|Updated|Updated|Updated|Updated|Updated|Updated|Updated|Updated"
  For $i = 0 To $iRows - 1
    $item = Random( $idLVItem0+$i*10, $idLVItem0+($i+1)*10-1, 1 )
    GUICtrlSetData( $item, $text )
  Next
EndFunc

 

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

×