473,722 Members | 2,240 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 15095
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
3324
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
3222
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
2306
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
2238
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
2312
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
2285
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
2038
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
4427
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
1387
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.
1
9157
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
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
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...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
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...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
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.