Jump to content

Creating treeview with childs and grandchilds


Tipulatoid
 Share

Recommended Posts

Hello

I have, for example, the following files in Script dir:

2009=09=19=23+23+54=Alexa_M.let

2009=09=19=23+23+55=Alexa_M.let

2009=09=19=23+23+56=Alexa_M.let

2009=09=19=23+23+57=Markovo.let

2009=09=19=23+25+35=Alexa_M.let

2009=09=19=23+25+37=Bay.let

2009=09=19=23+25+38=Alexa_M.let

2009=09=22=23+25+39=Alexa_M.let

2009=09=19=23+25+45=Geroy.let

2009=11=20=00+25+35=Alexa_M.let

The mask is:

Year=MonthNum=Date=Time=Name.extension

I need to get the tree view like this:

09 2009 ; parent1

|

|-- Alexa_M ;child1.1

| |

| |-- 19 23+23+54 ;grandchild1.1.1

| |-- 19 23+23+55 ;grandchild1.1.2

| |-- 19 23+23+56 ;grandchild1.1.3

| |-- 19 23+25+35 ;grandchild1.1.4

| |-- 19 23+25+38 ;grandchild1.1.5

| |-- 22 23+25+39 ;grandchild1.1.6

|

|-- Markovo ;child1.2

| |

| |-- 19 23+23+57 ;grandchild1.2.1

|

|-- Bay ;child1.3

| |

| |-- 19 23+25+37 ;grandchild1.3.1

| |

|-- Geroy ;child1.4

| |

| |--19 23+25+45 ;grandchild1.4.1

| |

|

|

11 2009 ;parent2

|

|-- Alexa_M ;child2.1

| |

| |--20 00+25+35 ;grandchild2.1.1

| |

Can you help with this? Thank you.

Edited by Tipulatoid
Link to comment
Share on other sites

Solved by Loopback from Russian Autoit Forum Many thanks to him.

Dim $nFileCount = 10
Dim $aFiles[$nFileCount]
$aFiles[0] = "2009=09=19=23+23+54=Alexa_M.let"
$aFiles[1] = "2009=09=19=23+23+55=Alexa_M.let"
$aFiles[2] = "2009=09=19=23+23+56=Alexa_M.let"
$aFiles[3] = "2009=09=19=23+23+57=Markovo.let"
$aFiles[4] = "2009=09=19=23+25+35=Alexa_M.let"
$aFiles[5] = "2009=09=19=23+25+37=Bay.let"
$aFiles[6] = "2009=09=19=23+25+38=Alexa_M.let"
$aFiles[7] = "2009=09=22=23+25+39=Alexa_M.let"
$aFiles[8] = "2009=09=19=23+25+45=Geroy.let"
$aFiles[9] = "2009=11=20=00+25+35=Alexa_M.let"

; Преобразуем имена файлов в двумерный список узлов
Dim $aItems[$nFileCount][3]
For $i = 0 To $nFileCount - 1
    $aResult = StringRegExp($aFiles[$i], "(\d{4})=(\d{2})=(\d{2})=(\d{2}\+\d{2}\+\d{2})=(\w+)\.let", 1) 
    ; тут надо проверочку, что регэксп отработал
    $aItems[$i][0] = $aResult[1] & " " & $aResult[0]
    $aItems[$i][1] = $aResult[4]
    $aItems[$i][2] = $aResult[2] & " " & $aResult[3]
Next

; Все элементы дерева храним во вложенных двумерных массивах
; Каждая строка массива: Имя узла, хэндл, список потомков
; Количество потомков узла в нулевом элементе
Dim $aRoot[1][3] = [[0,0,0]]

$hGUI = GUICreate("")
$hTree = GUICtrlCreateTreeView(5, 5, 350, 350)

; Заполним дерево
For $i = 0 To UBound($aItems) - 1
    _FillTree($aRoot, $aItems, $i, $hTree)
Next

GUISetState()
While 1
Wend

; Функции
Func _ItemIndex($aArray, $sItem)
    For $i = 0 To UBound($aArray)-1
        If $aArray[$i][0] == $sItem Then Return $i
    Next
    Return -1
EndFunc

Func _FillTree(ByRef $aArray, ByRef $aSource, $nSrcIndex, $hParent, $nLevel = 0)
    Local $hItem, $aTemp[1][3] = [[0,0,0]] 
    If $nLevel >= UBound($aSource, 2) Then Return
    $nIndex = _ItemIndex($aArray, $aSource[$nSrcIndex][$nLevel])
    If $nIndex = -1 Then 
        $aArray[0][0] += 1
        $nIndex = $aArray[0][0]
        ReDim $aArray[$nIndex+1][3]
        $aArray[$nIndex][0] = $aSource[$nSrcIndex][$nLevel]
        $aArray[$nIndex][1] = GUICtrlCreateTreeViewItem($aArray[$nIndex][0], $hParent)
        $aArray[$nIndex][2] = $aTemp
    EndIf
    $aTempItem = $aArray[$nIndex][2]
    _FillTree($aTempItem, $aSource, $nSrcIndex, $aArray[$nIndex][1], $nLevel + 1)
    $aArray[$nIndex][2] = $aTempItem
EndFunc
Edited by Tipulatoid
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...