473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Save/Load Treeview

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
14 15019
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
"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
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
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

"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
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
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
"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
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
"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

"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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alexander | last post by:
Hi! I need to write an app that downloads an email (pop3), and saves it to a file. The file should be opened again and parsed to get subject, body, attachments... Inline-images and other...
9
by: ukjock | last post by:
I am very new to the whole Visual Basic .net scene, and I am trying to get to grips with it... I thought I would try and learn a programming language, and I was advised on vb.net. I have already...
12
by: John | last post by:
Hi Is there a way to save the layout of controls (position, size, visibility, appearance etc.) to a file (xml?) and also be able to load the layout from a file? The idea being that these file...
2
by: Polaris | last post by:
Hi Experts: I'm using ASP.NET 2.0. I'm using a TreeView control with a design-time configured XmlDataSource (an XML file). I use the TreeView control as a "message board" with each node...
2
by: =?Utf-8?B?SnVhbiBEZW50?= | last post by:
Hi, I am using XmlWriter/XmlReader to save.load classes. However, one of the members of one class is of type Type. How can I write and then read that as Xml? -- Thanks in advance, Juan...
0
Ensonix
by: Ensonix | last post by:
I found a post about this, and it had some C# code that wouldn't convert, and when I finally got it converted it didn't work in .NET 1.1. So I made a few changes to the converted VB version and now...
7
by: Marren02 | last post by:
Hi, I have looked on the internet for quite some time concerning this issue The problem is loads and loads and loads of people use their examples instead of simply stating what code you use...
10
by: Marren02 | last post by:
Hi, I recently just unsubscribed my other thread due to the fact that it went against the posting regulations... If you feel offended by what I posted, I apologize I need Code for a save...
1
by: De Ward | last post by:
I have created a form that allows the user to upload an image, type a description in a rich textbox, type the name in one textbox, enter in the date of when completed and expected to be completed,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.