<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS + WSO реализация TreeView]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8395&amp;type=atom" />
	<updated>2013-08-23T06:44:53Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8395</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74887#p74887" />
			<content type="html"><![CDATA[<p>В чем моя ошибка?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-08-23T06:44:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74887#p74887</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74422#p74422" />
			<content type="html"><![CDATA[<p>Написал такой код. Не работает <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /><br /></p><div class="codebox"><pre><code>Set o = WScript.CreateObject(&quot;Scripting.WindowSystemObject&quot;)
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = o.CreateForm(0,0,0,0)
f.ClientWidth = 500
f.ClientHeight = 300
f.CenterControl()

Set Button = f.CreateButton(240,100,75,25,&quot;Checked&quot;)
Button.OnClick = GetRef(&quot;ShowChecked&quot;)

Set Button2 = f.CreateButton(240,140,75,25,&quot;Save&quot;)
Button2.OnClick = GetRef(&quot;SaveChecked&quot;)

Set Button3 = f.CreateButton(240,180,75,25,&quot;Load&quot;)
Button3.OnClick = GetRef(&quot;LoadChecked&quot;)

Set TreeView = f.CreateTreeView(0,0,0,0) 
TreeView.Align = o.Translate(&quot;AL_CLIENT&quot;) 
TreeView.CheckBoxes = true

Set Root = TreeView.Items.Add(&quot;1&quot;)
BuildTree Root, 4, 3
Root.Expand(false)

Set t = o.CreateTimer()
t.Interval = 100
t.OnExecute = GetRef(&quot;OnTimer&quot;)
t.Active = true

Sub BuildTree(Root, Levels, Items)
    If Levels &gt; 0 Then
        For i = 1 To Items
            Set Node = Root.Add(Root.Text &amp; &quot;.&quot; &amp; CStr(i))
            BuildTree Node, Levels - 1, Items
        Next
    End If
End Sub

Sub ShowChecked(Sender)
    List = &quot;&quot;
    EnumChecked Root, List
    MsgBox List
End Sub

Sub SaveChecked(Sender)
Set txtFile = objFSO.CreateTextFile(&quot;d:\tree.txt&quot;, true, true)
    List = &quot;&quot;
    EnumChecked Root, List
    txtFile.write List
End Sub

Sub LoadChecked(Sender) &#039; Загружаем сохраненные строки
Set txtFile = objFSO.OpenTextFile(&quot;d:\tree.txt&quot;, 1)
txtFile.SkipLine
Do Until txtFile.AtEndOfStream &#039; Тут вызываем функцию для поиска по дереву
LoadCheck Root, List, txtFile.ReadLine
loop

End Sub

Sub EnumChecked(Root, List)
    If Root.Checked Then
        List = List &amp; vbCrLf &amp; Root.Text
    End If
    For i = 0 To Root.Count - 1
        Set Node = Root.Item(i)
        EnumChecked Node, List
    Next
End Sub

Sub LoadCheck(Root, List, treetext) &#039; Рекурсивный поиск и сравнение. Результата не дает =(
    If Root.Checked=false and Root.Text=treetext Then
       Root.Checked=True
    End If
    For i = 0 To Root.Count - 1
        Set Node = Root.Item(i)
        LoadCheck Node, List,  treetext
    Next
End Sub

Sub OnTimer(Sender)
    UpdateItems TreeView.Items
End Sub

Sub InitItems(Value)
    Dim Item
    Dim SubItem
    Dim i

    Set Item = Value
    Item.UserData = Item.Checked

    If Item.Count &gt; 0 Then
        For i = 1 To Item.Count
            Call InitItems(Item.Item(i-1))
        Next
    End If
End Sub

Sub UpdateItems(Value)
    Dim Item
    Dim SubItem
    Dim i

    Set Item = Value

    If Item.UserData &lt;&gt; Item.Checked Then
    Item.UserData = Item.Checked
    If Item.Count &gt; 0 Then
        For i = 1 To Item.Count
            Item.Item(i-1).Checked = Item.Checked
        Next
    End If
    End If

    If Item.Count &gt; 0 Then
    For i = 1 To Item.Count
        Call UpdateItems(Item.Item(i-1))
    Next
    End If
End Sub

InitItems TreeView.Items

f.Show()
o.Run()
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-08-12T08:29:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74422#p74422</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=74069#p74069" />
			<content type="html"><![CDATA[<p>Спасибо, ваше решение очень мне помогло. Но возник еще один &quot;нубский&quot; вопрос: как теперь проставить чекбоксы, считав данные из файла?<br />Допустим у меня есть текстовый файл со списком отмеченных позиций, как на них проставить галочки?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-07-29T06:34:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=74069#p74069</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73174#p73174" />
			<content type="html"><![CDATA[<p>Вот пример, который использует рекурсию для построения дерева и для поиска отмеченных чекбоксов.<br /></p><div class="codebox"><pre><code>
Set o = WScript.CreateObject(&quot;Scripting.WindowSystemObject&quot;)

Set f = o.CreateForm(0,0,0,0)
f.ClientWidth = 500
f.ClientHeight = 300
f.CenterControl()

Set Button = f.CreateButton(240,100,75,25,&quot;Checked&quot;)
Button.OnClick = GetRef(&quot;ShowChecked&quot;)

Set TreeView = f.CreateTreeView(0,0,0,0) 
TreeView.Align = o.Translate(&quot;AL_CLIENT&quot;) 
TreeView.CheckBoxes = true

Set Root = TreeView.Items.Add(&quot;1&quot;)
BuildTree Root, 4, 3
Root.Expand(false)

Set t = o.CreateTimer()
t.Interval = 100
t.OnExecute = GetRef(&quot;OnTimer&quot;)
t.Active = true

Sub BuildTree(Root, Levels, Items)
    If Levels &gt; 0 Then
        For i = 1 To Items
            Set Node = Root.Add(Root.Text &amp; &quot;.&quot; &amp; CStr(i))
            BuildTree Node, Levels - 1, Items
        Next
    End If
End Sub

Sub ShowChecked(Sender)
    List = &quot;&quot;
    EnumChecked Root, List
    MsgBox List
End Sub

Sub EnumChecked(Root, List)
    If Root.Checked Then
        List = List &amp; vbCrLf &amp; Root.Text
    End If
    For i = 0 To Root.Count - 1
        Set Node = Root.Item(i)
        EnumChecked Node, List
    Next
End Sub

Sub OnTimer(Sender)
    UpdateItems TreeView.Items
End Sub

Sub InitItems(Value)
    Dim Item
    Dim SubItem
    Dim i

    Set Item = Value
    Item.UserData = Item.Checked

    If Item.Count &gt; 0 Then
        For i = 1 To Item.Count
            Call InitItems(Item.Item(i-1))
        Next
    End If
End Sub

Sub UpdateItems(Value)
    Dim Item
    Dim SubItem
    Dim i

    Set Item = Value

    If Item.UserData &lt;&gt; Item.Checked Then
    Item.UserData = Item.Checked
    If Item.Count &gt; 0 Then
        For i = 1 To Item.Count
            Item.Item(i-1).Checked = Item.Checked
        Next
    End If
    End If

    If Item.Count &gt; 0 Then
    For i = 1 To Item.Count
        Call UpdateItems(Item.Item(i-1))
    Next
    End If
End Sub

InitItems TreeView.Items

f.Show()
o.Run()
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-06-21T05:39:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73174#p73174</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73170#p73170" />
			<content type="html"><![CDATA[<p>Сделайте пример с нужным вам количеством уровней, и попробуем.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-06-21T03:34:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73170#p73170</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73158#p73158" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><div class="quotebox"><blockquote><p>Но что делать если дерево имеет &quot;ветвистость&quot;, по 5-6 вложений?</p></blockquote></div><p>Использовать рекурсию.</p></blockquote></div><p>Вооот тут то и затык. Обращаться 5-6 раз, копируя 5-6 вложеных условий, к дочерним элементам не хочется. А как построить правильно, догнать не могу. См. 1 пост.</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-06-20T16:00:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73158#p73158</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73155#p73155" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Mat Skywalker пишет:</cite><blockquote><p>Вы забыли одну строку впереди<br /></p><div class="codebox"><pre><code>set root=Tree.Items</code></pre></div></blockquote></div><p>Нет, не забыл. Она ведь уже есть в примере в посте №1.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-06-20T13:33:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73155#p73155</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73154#p73154" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Но что делать если дерево имеет &quot;ветвистость&quot;, по 5-6 вложений?</p></blockquote></div><p>Использовать рекурсию.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2013-06-20T13:04:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73154#p73154</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73146#p73146" />
			<content type="html"><![CDATA[<p>Вы забыли одну строку впереди<br /></p><div class="codebox"><pre><code>set root=Tree.Items</code></pre></div><p>Спасибо, ваш метод работает. Но что делать если дерево имеет &quot;ветвистость&quot;, по 5-6 вложений?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-06-20T12:01:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73146#p73146</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73144#p73144" />
			<content type="html"><![CDATA[<p>Я не знаток этого компонента, но вот так вроде работает:<br /></p><div class="codebox"><pre><code>
If Root.Checked Then
    MsgBox Root.Text
End If
For i = 0 To Root.Count - 1
    Set Node = Root.Item(i)
    If Node.Checked Then
        MsgBox Node.Text
    End If
    For j = 0 To Node.Count - 1
        Set Leaf = Node.Item(j)
        If Leaf.Checked Then
            MsgBox Leaf.Text
        End If
    Next
Next
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2013-06-20T10:46:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73144#p73144</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73141#p73141" />
			<content type="html"><![CDATA[<p>Пока ничего умнее чем это не придумал:<br /></p><div class="codebox"><pre><code>for i=0 to Tree.Items.Count-1
if  Tree.Items(i).Checked=True then msgbox Tree.Items(i).Text
next</code></pre></div><p>А вот как пройти все дерево?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-06-20T08:23:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73141#p73141</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS + WSO реализация TreeView]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72978#p72978" />
			<content type="html"><![CDATA[<p>Пытаюсь использовать такую замечательную штуку как WSO. О этой технологии тут уже писали. <a href="http://forum.script-coding.com/viewtopic.php?id=3906">http://forum.script-coding.com/viewtopic.php?id=3906</a><br />Возник такой вопрос. В данном примере TreeView реализована простановка &quot;галочек&quot; по всем дочерним элементам дерева. Данный пример прислал мне сам автор, за что ему большое спасибо.</p><div class="quotebox"><blockquote><p>Здравствуйте</p><p>Инструмент для перебора есть, но нет события, которое вызывается в момент смены переключателя.<br />Будет добавлено в будущем.</p><p>Пока как-то так можно:</p></blockquote></div><div class="codebox"><pre><code>Set o = WScript.CreateObject(&quot;Scripting.WindowSystemObject&quot;)

Set f = o.CreateForm(0,0,0,0)
f.ClientWidth = 500
f.ClientHeight = 300
f.CenterControl()

Set TreeView = f.CreateTreeView(0,0,0,0) 
TreeView.Align = o.Translate(&quot;AL_CLIENT&quot;) 
TreeView.CheckBoxes = true

Set Root = TreeView.Items.Add(&quot;1&quot;)

For counter = 1 To 10
    Set Item = Root.Add(CStr(counter))
    For i = 1 To 10
        Set Item1 = Item.Add(CStr(counter)+&quot;.&quot;+CStr(i))
    Next
Next

Root.Expand(true)

Set t = o.CreateTimer()
t.Interval = 100
t.OnExecute = GetRef(&quot;OnTimer&quot;)
t.Active = true

Sub OnTimer(Sender)
    UpdateItems TreeView.Items
End Sub

Sub InitItems(Value)
    Dim Item
    Dim SubItem
    Dim i

    Set Item = Value
    Item.UserData = Item.Checked

    If Item.Count &gt; 0 Then
        For i = 1 To Item.Count
            Call InitItems(Item.Item(i-1))
        Next
    End If
End Sub


Sub UpdateItems(Value)
    Dim Item
    Dim SubItem
    Dim i

    Set Item = Value

    If Item.UserData &lt;&gt; Item.Checked Then
    Item.UserData = Item.Checked
    If Item.Count &gt; 0 Then
        For i = 1 To Item.Count
            Item.Item(i-1).Checked = Item.Checked
        Next
    End If
    End If

    If Item.Count &gt; 0 Then
    For i = 1 To Item.Count
        Call UpdateItems(Item.Item(i-1))
    Next
    End If
End Sub

InitItems TreeView.Items

f.Show()
o.Run()
</code></pre></div><p>Теперь собственно вопрос к знатокам. <br />Как перебрать все элементы коллекции и узнать где &quot;галочка&quot; стоит, а где нет?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2013-06-16T12:20:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72978#p72978</id>
		</entry>
</feed>
