473,396 Members | 2,102 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,396 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 15035
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.