473,836 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15106
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******** *******@TK2MSFT NGP11.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******** ******@tk2msftn gp13.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(tr eeview.Nodes(i) )
Next

End Sub

Public Sub PopulateTree(By Val 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 SelectedImageIn dex As Integer
Public Nodes() As TreeNodeData

Public Sub New(ByVal node As TreeNode)

Me.Text = node.Text
Me.ImageIndex = node.ImageIndex
Me.SelectedImag eIndex = node.SelectedIm ageIndex

If node.Nodes.Coun t = 0 Then Exit Sub

ReDim Nodes(node.Node s.Count - 1)
For i As Integer = 0 To node.Nodes.Coun t - 1
Nodes(i) = New TreeNodeData(no de.Nodes(i))
Next

End Sub

Public Function ToTreeNode() As TreeNode
ToTreeNode = New TreeNode(Me.Tex t, Me.ImageIndex,
Me.SelectedImag eIndex)

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

End Structure

</Code>

Then to use it:

<Code>

Private SubLoadButton_C lick(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button3.Click

Dim ser As New
System.Xml.Seri alization.XmlSe rializer(GetTyp e(TreeViewData) )
Dim file As New System.IO.FileS tream("C:\Temp\ TreeView.xml",
IO.FileMode.Ope nOrCreate)
Dim writer As New System.Xml.XmlT extWriter(file, Nothing)

ser.Serialize(w riter, New TreeViewData(Tr eeView1))

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

End Sub

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button4.Click

Dim ser As New
System.Xml.Seri alization.XmlSe rializer(GetTyp e(TreeViewData) )
Dim file As New System.IO.FileS tream("C:\Temp\ TreeView.xml",
IO.FileMode.Ope n)
Dim reader As New System.Xml.XmlT extReader(file)

Dim treeData As TreeViewData = CType(ser.Deser ialize(reader),
TreeViewData)
treeData.Popula teTree(TreeView 1)

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.bl udog.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(tr eeview.Nodes(i) )
Next

End Sub

Public Sub PopulateTree(By Val 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 SelectedImageIn dex As Integer
Public Nodes() As TreeNodeData

Public Sub New(ByVal node As TreeNode)

Me.Text = node.Text
Me.ImageIndex = node.ImageIndex
Me.SelectedImag eIndex = node.SelectedIm ageIndex

If node.Nodes.Coun t = 0 Then Exit Sub

ReDim Nodes(node.Node s.Count - 1)
For i As Integer = 0 To node.Nodes.Coun t - 1
Nodes(i) = New TreeNodeData(no de.Nodes(i))
Next

End Sub

Public Function ToTreeNode() As TreeNode
ToTreeNode = New TreeNode(Me.Tex t, Me.ImageIndex,
Me.SelectedImag eIndex)

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

End Structure>
</Code>

Then to use it:

<Code>
Private Sub SaveButton_Clic k(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles SaveButton.Clic k

Dim ser As New
System.Xml.Seri alization.XmlSe rializer(GetTyp e(TreeViewData) )
Dim file As New System.IO.FileS tream("C:\Temp\ TreeView.xml",
IO.FileMode.Cre ate)
Dim writer As New System.Xml.XmlT extWriter(file, Nothing)

ser.Serialize(w riter, New TreeViewData(Tr eeView1))

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

End Sub

Private Sub LoadButton_Clic k(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles LoadButton.Clic k

Dim ser As New
System.Xml.Seri alization.XmlSe rializer(GetTyp e(TreeViewData) )
Dim file As New System.IO.FileS tream("C:\Temp\ TreeView.xml",
IO.FileMode.Ope n)
Dim reader As New System.Xml.XmlT extReader(file)

Dim treeData As TreeViewData = CType(ser.Deser ialize(reader),
TreeViewData)
treeData.Popula teTree(TreeView 1)

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

End Sub
</Code>

Hope this helps

Blu.


Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3330
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 attachments, priority-settings and receipt-notification should be
9
3228
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 come across my first problem, of saving a combobox. I want to save the contents of a combobox and the reload the contents when the form re-loads. Any advise and any great Idiots guide website's? Thanks for your help
12
2318
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 scan serve as templates for different clients who may have different preferences. Is someone has worked with this and can post some code examples then that would be highly appreciated.
2
2242
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 representing a message. I noticed that the TreeView loads alright from the XML file but did not save anything. I call the TreeView.Save() for each new node added into the TreeView. What I'm missing here? Thanks in advance!
2
2317
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 Dent, M.Sc.
0
2300
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 it works perfect, however I could find a post replay on that form, so I thought I'd put it here for anyone else searching. 'ENSONIX ENTERPRISES, INCORPORATED 'WEB: http://www.ensonix.com...
7
2045
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 heres what I want: Code for a save button --- --- ---
10
4440
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 button... this save button must be able to... ---save data! ---must have a save as function...obviously due to the fact that some data might be new ---Explore the windows directory as default I therefore also need code for a load button with the...
1
1392
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, also if it wasn't completed on time the user selects no to enter in the date it was completed. I just want to know how do you save the inputed data, load it, and print it as well? Attached is a screenshot of my project.
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10852
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9382
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.