Hi,
I have created a treeview called TreeView1.
In this treeview you can find several terms which are considered as Roots because they are at the first level of the treeview.
I have created a sub to import into a textfile the entire treeview.
Here is the code of this sub.
Now, if the user clicks on one root term and clicks after on the menuitem 'export to txt'i would like him to export to a txtfile [blue]ONLY THE ROOT and all its specific terms( all the terms which are below it in the treeview)[/blue]
Could you help me to code this ; perhaps i need to make changes to the existing code.
Thanks alot for all your precious help.
Best regards.
Nathalie
I have created a treeview called TreeView1.
In this treeview you can find several terms which are considered as Roots because they are at the first level of the treeview.
I have created a sub to import into a textfile the entire treeview.
Here is the code of this sub.
Code:
Private Sub ExportTreeViewToTxt(ByVal TreeView As TreeView, ByVal OutputPath As String)
Dim clsPrompt As SaveFileDialog
If Not IsNothing(OutputPath) Then
'open stream...
[green] 'use recursive function to write out file... [/green]
Dim clsOutStream As New System.IO.MemoryStream
Dim clsWriter As New System.IO.StreamWriter(clsOutStream)
ExportToText(TreeView1.Nodes, 0, clsOutStream)
[green] 'close stream... [/green]
clsOutStream.Flush()
clsOutStream.Close()
clsPrompt = New SaveFileDialog
clsPrompt.Title = "Select Output File"
clsPrompt.Filter = "Text Files {*.txt}|*.txt"
If clsPrompt.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
OutputPath = clsPrompt.FileName
End If
clsOutStream.Close()
End If
End Sub
Code:
Private Sub ExportToText(ByVal Nodes As TreeNodeCollection, ByVal Indentation As Integer, ByVal OutStream As System.IO.MemoryStream)
Dim clsOutStream As System.IO.MemoryStream
For Each clsNode As TreeNode In Nodes
[green] 'write out node at the specified indentation... [/green]
Dim clsWriter As New System.IO.StreamWriter(clsOutStream)
clsWriter.WriteLine(New String(" "c, Indentation * 4) & " - " & clsNode.Text)
[green] 'write out child nodes... [/green]
Call ExportToText(clsNode.Nodes, Indentation + 1, clsOutStream)
[green] ' flush stream.. [/green]
clsWriter.Flush()
clsOutStream.Position = 0
Dim clsReader As New System.IO.StreamReader(clsOutStream)
MessageBox.Show(clsReader.ReadToEnd())
Next
End Sub
Could you help me to code this ; perhaps i need to make changes to the existing code.
Thanks alot for all your precious help.
Best regards.
Nathalie