MuffettsMan Posted April 9, 2015 Share Posted April 9, 2015 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 More sharing options...
Solution JohnOne Posted April 9, 2015 Solution Share Posted April 9, 2015 Change... For $i = 1 To 50 To... For $i = 0 To 50 MuffettsMan 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
MuffettsMan Posted April 9, 2015 Author Share Posted April 9, 2015 OMG i'm too tired to think atm but yah that works Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
MuffettsMan Posted April 9, 2015 Author Share Posted April 9, 2015 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! Link to comment Share on other sites More sharing options...
MuffettsMan Posted April 9, 2015 Author Share Posted April 9, 2015 got tired of trying to figure it out.. easier to just delete the first element of the array Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
kylomas Posted April 9, 2015 Share Posted April 9, 2015 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 MuffettsMan 1 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 More sharing options...
MuffettsMan Posted April 9, 2015 Author Share Posted April 9, 2015 thx kylomas that def is the cleaner solution Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
kylomas Posted April 9, 2015 Share Posted April 9, 2015 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. MuffettsMan 1 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now