Tomoya Posted December 4, 2012 Share Posted December 4, 2012 (edited) I have a file that I am trying to add to a list view that has multiple columns. I am having a problem getting it to add the correct items to the correct subitem's column. I think I almost have it but I'm sure I am missing some small thing. The files looks as such. 1;2;3;4;5;6 Here is the function. Func _FillList() $array = 1 $data = 1 Local $file = @ScriptDir & "" & "mob.txt" $data = FileRead($file) $array = StringSplit($data, ";", 1) For $n = 1 To UBound($array) - 1 If Mod($n, 2) Then $subitem = _GUICtrlListView_AddItem($ListView, $array[$n]) Else _GUICtrlListView_AddSubItem($ListView, $subitem, $array[$n], 1) $a = UBound($array) - 1 If $n + 1 > $a Then ExitLoop Else _GUICtrlListView_AddSubItem($ListView, $subitem, $array[$n + 1], 2) EndIf EndIf Next EndFunc ;===>_FillList Is there a simple way to just tell it to move to the next item in the loop? Currently the way it is displaying is 1 | 2 | 3 3 | 4 | 5 5 | 6 Edited December 4, 2012 by Tomoya Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2012 Moderators Share Posted December 4, 2012 Tomoya, And what do you want it to look like? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tomoya Posted December 4, 2012 Author Share Posted December 4, 2012 (edited) Tomoya, And what do you want it to look like? M23 Ha I guess that would be needed! Just a simple. 1 | 2 | 3 4 | 5 | 6 Edited December 4, 2012 by Tomoya Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2012 Moderators Share Posted December 4, 2012 Tomoya,I would Step through the array in the required number of columns - like this:#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("Test", 500, 500) $cListView = GUICtrlCreateListView("", 10, 10, 310, 200) _GUICtrlListView_AddColumn($cListView, "Col 1", 100) _GUICtrlListView_AddColumn($cListView, "Col 2", 100) _GUICtrlListView_AddColumn($cListView, "Col 3", 100) GUISetState() ; Simulate loading file $sData = "1;2;3;4;5;6" $aData = StringSplit($sData, ";") For $i = 1 To $aData[0] Step 3 $iItem = _GUICtrlListView_AddItem($cListView, $aData[$i]) _GUICtrlListView_AddSubItem($cListView, $iItem, $aData[$i + 1], 1) _GUICtrlListView_AddSubItem($cListView, $iItem, $aData[$i + 2], 2) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndMuch simpler. M23 Tomoya 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tomoya Posted December 4, 2012 Author Share Posted December 4, 2012 Tomoya, I would Step through the array in the required number of columns - like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("Test", 500, 500) $cListView = GUICtrlCreateListView("", 10, 10, 310, 200) _GUICtrlListView_AddColumn($cListView, "Col 1", 100) _GUICtrlListView_AddColumn($cListView, "Col 2", 100) _GUICtrlListView_AddColumn($cListView, "Col 3", 100) GUISetState() ; Simulate loading file $sData = "1;2;3;4;5;6" $aData = StringSplit($sData, ";") For $i = 1 To $aData[0] Step 3 $iItem = _GUICtrlListView_AddItem($cListView, $aData[$i]) _GUICtrlListView_AddSubItem($cListView, $iItem, $aData[$i + 1], 1) _GUICtrlListView_AddSubItem($cListView, $iItem, $aData[$i + 2], 2) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Much simpler. M23 That worked perfectly... I had no idea about step and for what I was trying to accomplish it is much more efficient. I have a personal question for you if you don't mind. What is your background in AutoIt? I see that you answer almost every question with a elegant and simple solution posted here and that is awesome! Do you currently have any AutoIt challenges that "Stump" you right now? Thanks for helping the community. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2012 Moderators Share Posted December 4, 2012 Tomoya,What is your background in AutoIt?I discovered AutoIt shortly before I joined the forum - but I have been coding as a hobby for some 45 years (mostly FORTRAN, BASIC (of several dialects), ASM, and a few others). any AutoIt challenges that "Stump" you right now?That would be telling! Thanks for helping the communityIt is my pleasure to be here. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted December 4, 2012 Share Posted December 4, 2012 (edited) Tomoya, (bowing to M23...) This may interest you. This uses some of the techniques used in _arraydisplay with automatic column adjustment (code from M23). I find this simpler than using the listview UDF's, although my experience with listview controls is limited. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> local $col_N = 50 ; number of columns in listview local $item_N = 128 ; number of test entries to generate local $col_W = @DesktopWidth/$col_N local $gui010 = GUICreate("Test LV", ($col_W * $col_N) - 10, 500) local $clsize = wingetclientsize($gui010) local $lst010 = GUICtrlCreateListView('', 0, 0, $clsize[0], $clsize[1] - 100,-1,bitor($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) for $1 = 1 to $col_N _GUICtrlListView_AddColumn($lst010, 'Col ' & stringformat('%02i',$1), $col_W) Next ; generate a bunch of delimited test data. The '|' is the column delimiter, the ';' is the item delimiter local $sdata for $1 = 1 to $item_N $sdata &= $1 & '|' if mod($1,$col_N) = 0 then $sdata &= ';' next local $adata = stringsplit($sdata,';',2) For $i = 0 To ubound($aData) - 1 GUICtrlCreateListViewItem($aData[$i], $lst010) Next ; adjust column widths to the wider of column header or column data ; ; This magic compliments of Melba23 local $ghw, $gdw, $gtw for $1 = 0 to _GUICtrlListView_GetColumnCount($lst010) + 1 _GUICtrlListView_SetColumnWidth($lst010, $1, $LVSCW_AUTOSIZE_USEHEADER) $ghw = _GUICtrlListView_GetColumnWidth($lst010, $1) _GUICtrlListView_Setcolumnwidth($lst010, $1, $LVSCW_AUTOSIZE) $gdw = _GUICtrlListView_GetColumnWidth($lst010, $1) if $ghw > $gdw then _GUICtrlListView_Setcolumnwidth($lst010, $1, $ghw) $gtw += $ghw Else $gtw += $gdw endif next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd kylomas Edited December 4, 2012 by 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 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