MuffettsMan

GUICtrlListView_AddSubItem Bug? (error when looping)

8 posts in this topic

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!

Share this post


Link to post
Share on other sites



OMG >_< i'm too tired to think atm but yah that works :D


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

Share this post


Link to post
Share on other sites

oh now i know why i started at 1... the first row of data was a header row returned from sqlite yet for some reason when u skip 0 it bombs


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

Share this post


Link to post
Share on other sites

got tired of trying to figure it out.. easier to just delete the first element of the array :D


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

Share this post


Link to post
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

1 person likes this

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

Share this post


Link to post
Share on other sites

thx kylomas that def is the cleaner solution


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

Share this post


Link to post
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.

1 person likes this

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

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