By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,165 Members | 1,916 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,165 IT Pros & Developers. It's quick & easy.

Save/Load Treeview

P: n/a
How do I save/load the contents of a Treeview to a file?
I have found several good examples written i VB6, but not a single one for
VB.NET.

Please help.

----
Tim
Nov 21 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Mr.D,

There are so much samples for loading a Treeview, I think you need a very
special when no one did fit you.

What is so special that no one was good?

Cor
Nov 21 '05 #2

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote
There are so much samples for loading a Treeview, I think you need a very
special when no one did fit you.
I diddn't find a single Load+Save example for VB.NET
What is so special that no one was good?

Nothing special. I dont really care how the contenst are stored.

I've searched on
http://www.planet-source-code.com/
http://www.google.com/
and the Community search in MSDN 2005 Express and I came up whith nothing.

As said, I found many good VB6 examples, but I dont have the skilles of
rewriting them in .NET.
That's why I cried out for help in here.

----
Tim
Nov 21 '05 #3

P: n/a
Mr. D.

The threeview is not really a file related control, when you want to do it
you have to take the nodes from the tree and write them, therefore you will
probably not get easily a sample.

However what you ask looks directly to using a treeview with xmldoc

Beneath the links where I have searched this newsgroup for "treeview and
xml", there should be an example between it. It do not have it myself at the
moment.

http://tinyurl.com/4kpmb

I hope this helps?

Cor
"Mr.D" <kj**@dlkhdlhjd.com>
....
"Cor Ligthert" <no************@planet.nl> wrote
There are so much samples for loading a Treeview, I think you need a very
special when no one did fit you.


I diddn't find a single Load+Save example for VB.NET
What is so special that no one was good?

Nothing special. I dont really care how the contenst are stored.

I've searched on
http://www.planet-source-code.com/
http://www.google.com/
and the Community search in MSDN 2005 Express and I came up whith nothing.

As said, I found many good VB6 examples, but I dont have the skilles of
rewriting them in .NET.
That's why I cried out for help in here.

----
Tim

Nov 21 '05 #4

P: n/a
Tym
On Wed, 20 Oct 2004 12:47:34 +0200, "Mr.D" <kj**@dlkhdlhjd.com> wrote:
How do I save/load the contents of a Treeview to a file?
I have found several good examples written i VB6, but not a single one for
VB.NET.


Can't you download the vb6 version and use the upgrade wizard to
convert it for you??
Nov 21 '05 #5

P: n/a

"Mr.D" <kj**@dlkhdlhjd.com> schrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP11.phx.gbl...
"Cor Ligthert" <no************@planet.nl> wrote
There are so much samples for loading a Treeview, I think you need a very special when no one did fit you.


I diddn't find a single Load+Save example for VB.NET
What is so special that no one was good?

Nothing special. I dont really care how the contenst are stored.

I've searched on
http://www.planet-source-code.com/
http://www.google.com/
and the Community search in MSDN 2005 Express and I came up whith nothing.

As said, I found many good VB6 examples, but I dont have the skilles of
rewriting them in .NET.
That's why I cried out for help in here.

----
Tim


Hi Tim,

here is an example inC#
http://www.codeproject.com/cs/miscctrl/loadandsave.asp
with http://www.kamalpatel.net/ConvertCSharp2VB.aspx convert it to VB.net

Greeting

Thomas
Nov 21 '05 #6

P: n/a
Search for "TreeView" in this linked page:
http://www.vb-helper.com/index_files...rectories.html
There are a few examples that may help you.
-nate

"Mr.D" <kj**@dlkhdlhjd.com> wrote in message
news:u9**************@tk2msftngp13.phx.gbl...
How do I save/load the contents of a Treeview to a file?
I have found several good examples written i VB6, but not a single one for
VB.NET.

Please help.

----
Tim

Nov 21 '05 #7

P: n/a
On Wed, 20 Oct 2004 12:47:34 +0200, "Mr.D" <kj**@dlkhdlhjd.com> wrote:
How do I save/load the contents of a Treeview to a file?
I have found several good examples written i VB6, but not a single one for
VB.NET.

Please help.

----
Tim


The following uses a couple of strucures to represent the Treeview in
it's simplest form and then serialization to persist the data to file:

<Code>

<Serializable()> Public Structure TreeViewData
Public Nodes() As TreeNodeData

Public Sub New(ByVal treeview As TreeView)
If treeview.Nodes.Count = 0 Then Exit Sub

ReDim Nodes(treeview.Nodes.Count - 1)
For i As Integer = 0 To treeview.Nodes.Count - 1
Nodes(i) = New TreeNodeData(treeview.Nodes(i))
Next

End Sub

Public Sub PopulateTree(ByVal treeview As TreeView)

If Me.Nodes Is Nothing OrElse Me.Nodes.Length = 0 Then Exit
Sub
For i As Integer = 0 To Me.Nodes.Length - 1
treeview.Nodes.Add(Me.Nodes(i).ToTreeNode)
Next

End Sub

End Structure

<Serializable()> Public Structure TreeNodeData

Public Text As String
Public ImageIndex As Integer
Public SelectedImageIndex As Integer
Public Nodes() As TreeNodeData

Public Sub New(ByVal node As TreeNode)

Me.Text = node.Text
Me.ImageIndex = node.ImageIndex
Me.SelectedImageIndex = node.SelectedImageIndex

If node.Nodes.Count = 0 Then Exit Sub

ReDim Nodes(node.Nodes.Count - 1)
For i As Integer = 0 To node.Nodes.Count - 1
Nodes(i) = New TreeNodeData(node.Nodes(i))
Next

End Sub

Public Function ToTreeNode() As TreeNode
ToTreeNode = New TreeNode(Me.Text, Me.ImageIndex,
Me.SelectedImageIndex)

If Me.Nodes Is Nothing OrElse Me.Nodes.Length = 0 Then Exit
Function
For i As Integer = 0 To Me.Nodes.Length - 1
ToTreeNode.Nodes.Add(Me.Nodes(i).ToTreeNode)
Next
End Function

End Structure

</Code>

Then to use it:

<Code>

Private SubLoadButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click

Dim ser As New
System.Xml.Serialization.XmlSerializer(GetType(Tre eViewData))
Dim file As New System.IO.FileStream("C:\Temp\TreeView.xml",
IO.FileMode.OpenOrCreate)
Dim writer As New System.Xml.XmlTextWriter(file, Nothing)

ser.Serialize(writer, New TreeViewData(TreeView1))

writer.Close()
file.Close()
file = Nothing

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button4.Click

Dim ser As New
System.Xml.Serialization.XmlSerializer(GetType(Tre eViewData))
Dim file As New System.IO.FileStream("C:\Temp\TreeView.xml",
IO.FileMode.Open)
Dim reader As New System.Xml.XmlTextReader(file)

Dim treeData As TreeViewData = CType(ser.Deserialize(reader),
TreeViewData)
treeData.PopulateTree(TreeView1)

reader.Close()
file.Close()
file = Nothing

End Sub

</Code>

Hope this helps

Blu.
Nov 21 '05 #8

P: n/a
"thomas wenning" no*******************@gmx.de wrote
here is an example inC#
http://www.codeproject.com/cs/miscctrl/loadandsave.asp
Thanks Thomas.
I don't know C# but it looks very promissing indeed.
with http://www.kamalpatel.net/ConvertCSharp2VB.aspx convert it to VB.net


The converter do convert the code, but unfortunatly I get errors when
pasting the code into VB.

----
Tim
Nov 21 '05 #9

P: n/a
On Wed, 20 Oct 2004 14:35:43 +0100, BluDog <ne**@nospam.bludog.net>
wrote:
On Wed, 20 Oct 2004 12:47:34 +0200, "Mr.D" <kj**@dlkhdlhjd.com> wrote:
How do I save/load the contents of a Treeview to a file?
I have found several good examples written i VB6, but not a single one for
VB.NET.

Please help.

----
Tim

The following uses a couple of strucures to represent the Treeview in
it's simplest form and then serialization to persist the data to file:
Sorry... couple of errors there on testing... try this.
<Code>

<Serializable()> Public Structure TreeViewData
Public Nodes() As TreeNodeData

Public Sub New(ByVal treeview As TreeView)
If treeview.Nodes.Count = 0 Then Exit Sub

ReDim Nodes(treeview.Nodes.Count - 1)
For i As Integer = 0 To treeview.Nodes.Count - 1
Nodes(i) = New TreeNodeData(treeview.Nodes(i))
Next

End Sub

Public Sub PopulateTree(ByVal treeview As TreeView)

If Me.Nodes Is Nothing OrElse Me.Nodes.Length = 0 Then Exit
Sub
For i As Integer = 0 To Me.Nodes.Length - 1
treeview.Nodes.Add(Me.Nodes(i).ToTreeNode)
Next

End Sub

End Structure

<Serializable()> Public Structure TreeNodeData

Public Text As String
Public ImageIndex As Integer
Public SelectedImageIndex As Integer
Public Nodes() As TreeNodeData

Public Sub New(ByVal node As TreeNode)

Me.Text = node.Text
Me.ImageIndex = node.ImageIndex
Me.SelectedImageIndex = node.SelectedImageIndex

If node.Nodes.Count = 0 Then Exit Sub

ReDim Nodes(node.Nodes.Count - 1)
For i As Integer = 0 To node.Nodes.Count - 1
Nodes(i) = New TreeNodeData(node.Nodes(i))
Next

End Sub

Public Function ToTreeNode() As TreeNode
ToTreeNode = New TreeNode(Me.Text, Me.ImageIndex,
Me.SelectedImageIndex)

If Me.Nodes Is Nothing OrElse Me.Nodes.Length = 0 Then Exit
Function
For i As Integer = 0 To Me.Nodes.Length - 1
ToTreeNode.Nodes.Add(Me.Nodes(i).ToTreeNode)
Next
End Function

End Structure>
</Code>

Then to use it:

<Code>
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles SaveButton.Click

Dim ser As New
System.Xml.Serialization.XmlSerializer(GetType(Tre eViewData))
Dim file As New System.IO.FileStream("C:\Temp\TreeView.xml",
IO.FileMode.Create)
Dim writer As New System.Xml.XmlTextWriter(file, Nothing)

ser.Serialize(writer, New TreeViewData(TreeView1))

writer.Close()
file.Close()
file = Nothing

End Sub

Private Sub LoadButton_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles LoadButton.Click

Dim ser As New
System.Xml.Serialization.XmlSerializer(GetType(Tre eViewData))
Dim file As New System.IO.FileStream("C:\Temp\TreeView.xml",
IO.FileMode.Open)
Dim reader As New System.Xml.XmlTextReader(file)

Dim treeData As TreeViewData = CType(ser.Deserialize(reader),
TreeViewData)
treeData.PopulateTree(TreeView1)

reader.Close()
file.Close()
file = Nothing

End Sub
</Code>

Hope this helps

Blu.


Nov 21 '05 #10

P: n/a
"BluDog" <ne**@nospam.bludog.net> wrote
The following uses a couple of strucures to represent the Treeview in
it's simplest form and then serialization to persist the data to file:

<Code></Code>
Outstanding code!
It ran directly out of the box :o)

Thanks for the help!
Hope this helps
Blu.


You are a lifesaver.

----
Tim
Nov 21 '05 #11

P: n/a

"Mr.D" <kj**@dlkhdlhjd.com> schrieb im Newsbeitrag
news:eO**************@TK2MSFTNGP09.phx.gbl...
"thomas wenning" no*******************@gmx.de wrote
here is an example inC#
http://www.codeproject.com/cs/miscctrl/loadandsave.asp
Thanks Thomas.
I don't know C# but it looks very promissing indeed.
with http://www.kamalpatel.net/ConvertCSharp2VB.aspx convert it to

VB.net
The converter do convert the code, but unfortunatly I get errors when
pasting the code into VB.

----
Tim


Hi Tim,

you can bind this c#-control to your project.

Regards

Thomas Wenning
Nov 21 '05 #12

P: n/a
"thomas wenning" <no*******************@gmx.de> wrote
you can bind this c#-control to your project.


Bind a .cs file to a VB project?

----
Tim
Nov 21 '05 #13

P: n/a
On Wed, 20 Oct 2004 16:04:38 +0200, "Mr.D" <kj**@dlkhdlhjd.com> wrote:

Tim

I have tidied it up into a better class and posted the sourcecode in
Zip format:

http://www.codeproject.com/useritems...Access_src.zip

There is a work in progress article here:

http://www.codeproject.com/useritems...DataAccess.asp

Hope this is useful.

Blu
Nov 21 '05 #14

P: n/a
"Tom John" <tj [at] decsixth [dot] co [dot] uk> wrote in message
news:7r********************************@4ax.com...
I have tidied it up into a better class and posted the sourcecode in
Zip format:

http://www.codeproject.com/useritems...Access_src.zip
There is a work in progress article here:

http://www.codeproject.com/useritems...DataAccess.asp

Hope this is useful.


I get a 404 on both links, but maby codeproject.com just needs to refresh
some files.
I'll check by later.

The code does however works outstaningly well.

----
Tim
Nov 21 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.