Jump to content

Recommended Posts

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

image.jpeg.e6958d100464e8b62c91800132970f7c.jpeg

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 by marko001
Posted (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: 

image.thumb.png.978ac971e67bd1a00cc6067efd0f7468.png

If I use _GUICtrlListView_AddArray($hListView_Tags,$hTags)

It fills in this way

image.png.a5a00e11889d4e93404f5a1a3017e438.png

 

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 by marko001
Posted (edited)
#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 by ioa747
re-corection

I know that I know nothing

Posted
1 hour ago, ioa747 said:
#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"

 

Posted (edited)
#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 by ioa747
optimize

I know that I know nothing

  • Solution
Posted (edited)

Another approach :

#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 by Nine
Posted (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 by CYCho
Posted
21 minutes ago, Nine said:

Another approach :

#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!

image.thumb.png.ca94f079a9b42885b6c5ed8092a55536.png

Thanks all guys!

 

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
×
×
  • Create New...