marko001 Posted January 20, 2024 Posted January 20, 2024 (edited) Hi all, I have an array $htags[13][3] where x,0 is a list of html tags divided by "|" (i.e. tag1|tag2|tag3|...) x,1 is 1 or 0 (1 if tag is available in HTML, otherwise 0) x,2 is a string (H1, H2, H3,H4,H5, H6, Title, Keywords, Description, Paragraphs, Anchors, Div, LI) Then I have a Listview: $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) $hListView_Tags = GUICtrlCreateListView("H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI", 96, 576, 818, 262, $iLVStyle, $iLVExtStyle) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 5, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 6, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 7, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 8, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 9, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 10, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 11, 65) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 12, 65) It appears like that. I need to fill every columns of the listview with equivalent Tag as in column 2 of $htags This achieved by splitting $aTags = StringSplit($htags[$i][0], "|", 2) I tried this: Func _fillListview($hTags, $hListView_Tags) For $i = 0 To UBound($htags) - 1 ; Split the tags in $htags[$i][0] Local $aTags = StringSplit($htags[$i][0], "|", 2) ; Add a new item to the ListView GUICtrlCreateListViewItem("", $hListView_Tags) ; Loop through the tags and set the corresponding subitem in the ListView For $j = 1 To UBound($aTags) - 1 _GUICtrlListView_SetItem($hListView_Tags, $aTags[$j], $i, $j - 1) Next ; Set the other columns in the ListView _GUICtrlListView_SetItem($hListView_Tags, $htags[$i][1], $i, UBound($aTags) - 1) Next EndFunc But it doesn't work properly. Can someone help me to sort it out? Thanks in advance, Marco Edited January 20, 2024 by marko001
argumentum Posted January 20, 2024 Posted January 20, 2024 StringSplit() makes 1 dimensional arrays. Therefore you'll need to make a 2 dimensional array [ 1 ][ iCount ] to _GUICtrlListView_AddArray() or add a GUICtrlCreateListViewItem() as in the example. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
marko001 Posted January 20, 2024 Author Posted January 20, 2024 6 hours ago, argumentum said: StringSplit() makes 1 dimensional arrays. Therefore you'll need to make a 2 dimensional array [ 1 ][ iCount ] to _GUICtrlListView_AddArray() or add a GUICtrlCreateListViewItem() as in the example. How can I manage it to create the 2d array?
ioa747 Posted January 20, 2024 Posted January 20, 2024 (edited) show an example of the $htags[13][3] array Edited January 20, 2024 by ioa747 I know that I know nothing
CYCho Posted January 20, 2024 Posted January 20, 2024 Once you have a listview and an array you can use _GUICtrlListView_AddArray() function. zPlayer - A Small Audio and Video Player
marko001 Posted January 20, 2024 Author Posted January 20, 2024 3 hours ago, ioa747 said: show an example of the $htags[13][3] array
marko001 Posted January 20, 2024 Author Posted January 20, 2024 (edited) 3 hours ago, CYCho said: Once you have a listview and an array you can use _GUICtrlListView_AddArray() function. Can you provide me an example? I tried but without luck: Given this array: If I use _GUICtrlListView_AddArray($hListView_Tags,$hTags) It fills in this way In this case, as example, I shoulfd see in column Title the following columns: 0 - La Tana dei Goblin 1 - Giochi da Tavolo e Giochi in Scatola Because $htags[6][2] = "Title" and the two titles are stringsplit($htags[6][0],2). These titles must be filled in proper listview column (i.e. TITLE one) Edited January 20, 2024 by marko001
ioa747 Posted January 20, 2024 Posted January 20, 2024 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> ;Example Array Local $aTags = "H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI" $aTags = StringSplit($aTags, "|", 2) _ArrayColInsert($aTags, 0) _ArrayColInsert($aTags, 0) For $i = 0 To UBound($aTags) - 1 $aTags[$i][1] = Random(0, 1, 1) If $aTags[$i][1] = 1 Then $aTags[$i][0] = "text" & $i Next ;~ _ArrayDisplay($aTags) _fillListview($aTags) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;-------------------------------------------------------------------------------------------------------------------------------- Func _fillListview($aTags) _ArrayTranspose($aTags) _ArraySort($aTags, 1) Local $iCnt = UBound($aTags, 2) ; columns count Local $iColWidth = 65 ; columns width ; Create GUI $hGUI = GUICreate("ListView Tags", ($iColWidth * $iCnt) + 30, 300) ; Create ListView $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) Local $hListView_Tags = GUICtrlCreateListView("", 2, 2, ($iColWidth * $iCnt) + 25, 268, $iLVStyle, $iLVExtStyle) GUISetState(@SW_SHOW) ; Add columns For $i = 0 To $iCnt -1 _GUICtrlListView_AddColumn($hListView_Tags, $aTags[0][$i], $iColWidth) Next _ArrayDelete($aTags, 0) _GUICtrlListView_AddArray($hListView_Tags, $aTags) EndFunc ;==>_fillListview Edited January 20, 2024 by ioa747 re-corection I know that I know nothing
marko001 Posted January 20, 2024 Author Posted January 20, 2024 1 hour ago, ioa747 said: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> ;Example Array Local $aTags = "H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI" $aTags = StringSplit($aTags, "|", 2) _ArrayColInsert($aTags, 0) _ArrayColInsert($aTags, 0) For $i = 0 To UBound($aTags) - 1 $aTags[$i][1] = Random(0, 1, 1) If $aTags[$i][1] = 1 Then $aTags[$i][0] = "text" & $i Next ;~ _ArrayDisplay($aTags) _fillListview($aTags) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;-------------------------------------------------------------------------------------------------------------------------------- Func _fillListview($aTags) _ArrayTranspose($aTags) _ArraySort($aTags, 1) Local $iCnt = UBound($aTags, 2) ; columns count Local $iColWidth = 65 ; columns width ; Create GUI $hGUI = GUICreate("ListView Tags", ($iColWidth * $iCnt) + 30, 300) ; Create ListView $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) Local $hListView_Tags = GUICtrlCreateListView("", 2, 2, ($iColWidth * $iCnt) + 25, 268, $iLVStyle, $iLVExtStyle) GUISetState(@SW_SHOW) ; Add columns For $i = 0 To $iCnt -1 _GUICtrlListView_AddColumn($hListView_Tags, $aTags[0][$i], $iColWidth) Next _ArrayDelete($aTags, 0) _GUICtrlListView_AddArray($hListView_Tags, $aTags) EndFunc ;==>_fillListview @ioa747 First of all thanks for your support. This doesn't solve completely. first column may contain several H1 tags (and several H2, Titles, ... tags) written with pipe division I.e.: $hTag[0][2] = "H1" $hTag[0][0] = "First Tag|Second Tag|Third Tag|" $hTag[6][2] = "Title" $hTag[6][0] = "First Title" $hTag[9][2] = "Paragraphs" $hTag[0][0] = "First Paragraph|Second Paragraph|" So the Filelist should be something like: H1 |H2 |H3|H4|H5|H6|Title |Keywords|Description|Paragraphs |... -----------+-------------+--+--+--+--+------------+--------+-----------+-------------------+--- First Tag | | | | | |First Title | | | First Paragraph | Second Tag | | | | | | | | | Second Paragraph | Third Tag | | | | | | | | | | That means the listview should be filled with all these tags "stringsplitted"
ioa747 Posted January 20, 2024 Posted January 20, 2024 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> ;Example Array Local $aTags = "H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI" $aTags = StringSplit($aTags, "|", 2) _ArrayColInsert($aTags, 0) _ArrayColInsert($aTags, 0) For $i = 0 To UBound($aTags) - 1 $aTags[$i][1] = 1 If $aTags[$i][1] = 1 Then $aTags[$i][0] = "zz|kk|uu|gg|text" & $i Next _fillListview($aTags) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;-------------------------------------------------------------------------------------------------------------------------------- Func _fillListview($aTags) Local $aColumns = "H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI" $aColumns = StringSplit($aColumns, "|", 2) Local $iCnt = UBound($aColumns) ; columns count Local $iColWidth = 65 ; columns width ; Create GUI $hGUI = GUICreate("ListView Tags", ($iColWidth * $iCnt) + 30, 300) ; Create ListView $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) Local $hListView_Tags = GUICtrlCreateListView("", 2, 2, ($iColWidth * $iCnt) + 25, 268, $iLVStyle, $iLVExtStyle) GUISetState(@SW_SHOW) ; Add columns For $i = 0 To $iCnt - 1 _GUICtrlListView_AddColumn($hListView_Tags, $aColumns[$i], $iColWidth) Next _ArrayColDelete($aTags, 1) _ArrayColDelete($aTags, 1) Local $aSplit, $iDif For $R = 0 To UBound($aTags) - 1 $aSplit = StringSplit($aTags[$R][0], "|", 2) $iDif = UBound($aSplit) - UBound($aTags, 2) If $iDif > 0 Then For $z = 1 To $iDif _ArrayColInsert($aTags, UBound($aTags, 2)) Next EndIf For $C = 0 To UBound($aSplit) - 1 $aTags[$R][$C] = $aSplit[$C] Next Next _ArrayTranspose($aTags) _GUICtrlListView_AddArray($hListView_Tags, $aTags) ;~ _ArrayDisplay($aTags) EndFunc ;==>_fillListview Edited January 20, 2024 by ioa747 optimize I know that I know nothing
Solution Nine Posted January 20, 2024 Solution Posted January 20, 2024 (edited) Another approach : expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> Local $hTag[13][3] $hTag[0][2] = "H1" $hTag[0][0] = "First Tag|Second Tag|Third Tag|" $hTag[6][2] = "Title" $hTag[6][0] = "First Title" $hTag[9][2] = "Paragraphs" $hTag[9][0] = "First Paragraph|Second Paragraph|" Local $sTags = "H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI" Local $aTags = StringSplit($sTags, "|", 2) Local $hGUI = GUICreate("ListView Tags", 1000, 300) Local $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) Local $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) Local $hListView_Tags = GUICtrlCreateListView($sTags, 5, 5, 980, 260, $iLVStyle, $iLVExtStyle) For $i = 0 To UBound($aTags) - 1 GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, $i, 75) Next For $i = 1 To 10 _GUICtrlListView_AddItem($hListView_Tags, "") Next GUISetState() Local $aTmp, $iCol For $i = 0 To UBound($hTag) - 1 If Not $hTag[$i][2] Then ContinueLoop $aTmp = StringSplit($hTag[$i][0], "|", $STR_NOCOUNT) $iCol = _ArraySearch($aTags, $hTag[$i][2]) For $j = 0 To UBound($aTmp) - 1 _GUICtrlListView_SetItemText($hListView_Tags, $j, $aTmp[$j], $iCol) Next Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ps. you don't have to do an _ArraySearch if first index of $hTag is always equal to the right column Edited January 20, 2024 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
CYCho Posted January 20, 2024 Posted January 20, 2024 (edited) 5 hours ago, marko001 said: Can you provide me an example? I tried but without luck: Your original array($htags) is the raw data. You should turn it into another array (say $aListView) with columns filled as you want to appear in the listview, and then use _GUICtrlListView_AddArray($hListView_Tags, $aListView). Edited January 20, 2024 by CYCho zPlayer - A Small Audio and Video Player
marko001 Posted January 20, 2024 Author Posted January 20, 2024 21 minutes ago, Nine said: Another approach : expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> Local $hTag[13][3] $hTag[0][2] = "H1" $hTag[0][0] = "First Tag|Second Tag|Third Tag|" $hTag[6][2] = "Title" $hTag[6][0] = "First Title" $hTag[9][2] = "Paragraphs" $hTag[9][0] = "First Paragraph|Second Paragraph|" Local $sTags = "H1|H2|H3|H4|H5|H6|Title|Keywords|Description|Paragraphs|Anchors|DIV|LI" Local $aTags = StringSplit($sTags, "|", 2) Local $hGUI = GUICreate("ListView Tags", 1000, 300) Local $iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS) Local $iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT) Local $hListView_Tags = GUICtrlCreateListView($sTags, 5, 5, 980, 260, $iLVStyle, $iLVExtStyle) For $i = 0 To UBound($aTags) - 1 GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, $i, 75) Next For $i = 1 To 10 _GUICtrlListView_AddItem($hListView_Tags, "") Next GUISetState() Local $aTmp, $iCol For $i = 0 To UBound($hTag) - 1 If Not $hTag[$i][2] Then ContinueLoop $aTmp = StringSplit($hTag[$i][0], "|", $STR_NOCOUNT) $iCol = _ArraySearch($aTags, $hTag[$i][2]) For $j = 0 To UBound($aTmp) - 1 _GUICtrlListView_SetItemText($hListView_Tags, $j, $aTmp[$j], $iCol) Next Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE PERFECT! Thanks all guys!
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