Jump to content

GUICtrlListView_AddSubItem Bug? (error when looping)


Go to solution Solved by JohnOne,

Recommended Posts

Trying to make a loop to populate a list view... this code is straight from the help file just made a while loop instead of hard coding values - it works with _GUICtrlListView_AddItem however nothing shows on _GUICtrlListView_AddSubItem

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

Example()

Func Example()
    Local $hImage, $hListView

    ; Create GUI
    GUICreate("ListView Add SubItem", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    GUISetState(@SW_SHOW)



    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

    ; Add items THIS IS THE CHANGE 
      For $i = 1 To 50
         ConsoleWrite("i: " & $i & @CRLF)
          _GUICtrlListView_AddItem($hListView, "Row " & $i & ": Col 1", $i)
          _GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i & ": Col 2", 1, 1)
          _GUICtrlListView_AddSubItem($hListView, $i, "Row " & $i & ": Col 3", 2, 2)
      Next

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Example straight from help file:

https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlListView_AddSubItem.htm

 

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

MuffetsMan,

You can do that or you do it this way...

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <sqlite.au3>

_sqlite_startup()
_Sqlite_open()
_sqlite_exec(-1, 'create table t1 (t1name, t1rank, t1serial)')
_sqlite_exec(-1, 'insert into t1 values ("Joe", "E1", 12345),("Al", "E2", 34567),("Sue", "E9", 98765);')
local $arows,$irows, $icols
_SQLite_GetTable2d(-1,'select * from t1;', $arows, $irows, $icols)

local $gui010 = guicreate('SQLite ListView Population Example')
local $aSize  = wingetclientsize($gui010)
local $lv010  = guictrlcreatelistview('Name|Rank|Serial #',0,0,$aSize[1],$aSize[0])

; generic routine to populate a listview from an SQLite returned 2D array
for $1 = 1 to ubound($arows) - 1
    _GUICtrlListView_AddItem($lv010, $arows[$1][0])
    for $2 = 1 to ubound($arows,2) - 1
        _GUICtrlListView_AddsubItem($lv010,$1-1, $arows[$1][$2], $2) ; $1-1 is the index of the item, $2 is the index of the sub-item
    next
next

guisetstate()

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch
WEnd

kylomas

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

Link to comment
Share on other sites

Your welcome.  Just wanted to show an example of populating a LV from an SQLite produced 2D array.  It sounded like you were mixing up _additem which uses a "0" offset and _addsubitem which uses a "1" offset.

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

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...