|
-
May 25th, 2000, 10:45 PM
#1
Thread Starter
New Member
How can a treeview control be saved after adding child and parents in run mode. It has to be save in a sequencial file? if so, How can it be done? do you have some tips?
-
May 25th, 2000, 11:37 PM
#2
Fanatic Member
Give this a whirl
This should do it. It is a bit basic at the minute, but i am sure you will be able to refine it.
It seems to work fine, which actually surprises me, as it is realtivley simple.
To run this you will need
Treeview called TreeView1
command button called cmdSave
command button called cmdLoad
command button called cmdClear
label called Label1 (not really necesary)
Code:
Option Explicit
Private Sub cmdClear_Click()
'clear the tree view
TreeView1.Nodes.Clear
End Sub
Private Sub cmdLoad_Click()
Dim strInput As String
Dim strNode() As String
'open the file
Open "myTest.txt" For Input As #1
Do While Not EOF(1)
'get one line
Line Input #1, strInput
'split the line on commas
strNode = Split(strInput, ",")
'If the parent is blank then we don't insert
If Trim$(strNode(0)) = "" Then
TreeView1.Nodes.Add , strNode(1), strNode(2), strNode(3)
Else
TreeView1.Nodes.Add strNode(0), strNode(1), strNode(2), strNode(3)
End If
Loop
Close #1
Label1.Caption = "Loaded Treeview."
End Sub
Private Sub cmdSave_Click()
Dim myNode As Node
Dim strNode As String
Dim strParent As String
Open "myTest.txt" For Output As #1
For Each myNode In TreeView1.Nodes
'if the parent is nothing then save ""
If myNode.Parent Is Nothing Then
strParent = ""
Else
strParent = myNode.Parent.Key
End If
'build a string to save
'"4" means tvwChild.
strNode = strParent & "," & "4" & "," & myNode.Key & "," & myNode.Text
'write the string to the file
Print #1, strNode
Next
Close #1
Label1.Caption = "Saved Treeview."
End Sub
Private Sub Form_Load()
TreeView1.Nodes.Add , , "root", "root"
TreeView1.Nodes.Add "root", tvwChild, "one", "1"
TreeView1.Nodes.Add "one", tvwChild, "onedotone", "1.1"
TreeView1.Nodes.Add "one", tvwChild, "onedottwo", "1.2"
TreeView1.Nodes.Add "root", tvwChild, "two", "2"
End Sub
Hope it hepls.
Regards
[Edited by Iain17 on 05-26-2000 at 06:05 PM]
Iain, thats with an i by the way!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|