473,394 Members | 2,168 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,394 software developers and data experts.

Searilizing a treeView Control

meh
I need to be able to persist a treeView to disk. I would like to save the
node text, tag, image and selected image. I have done this using vb but I
cant seem to translate from vb to vc#.
Can ne1 point me to documentation or samples that might help???
Thanks in advance
meh
Nov 16 '05 #1
4 3418
meh,

How did you do it in VB? Are you talking about VB6 or VB.NET? In
VB.NET (or C#), you will have to use the Serialization attribute, possibly
in conjunction with the ISerializable interface. Check out the section of
the .NET framework titled "Serializing Objects", located at (watch for line
wrap):

http://msdn.microsoft.com/library/de...ingobjects.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"meh" <no*************@cox.net> wrote in message
news:e8**************@TK2MSFTNGP12.phx.gbl...
I need to be able to persist a treeView to disk. I would like to save the
node text, tag, image and selected image. I have done this using vb but I
cant seem to translate from vb to vc#.
Can ne1 point me to documentation or samples that might help???
Thanks in advance
meh

Nov 16 '05 #2
meh
Thx Nicholas i did it in VB.net. I would be more than willing to share the
code so as to help me understand how to convert from vb to c# dotNet. I
found a vb.net to c#.net converter on the web but the converted code does
not work.
Thanks again I will have a look at the link you provided.

meh

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
meh,

How did you do it in VB? Are you talking about VB6 or VB.NET? In
VB.NET (or C#), you will have to use the Serialization attribute, possibly
in conjunction with the ISerializable interface. Check out the section of
the .NET framework titled "Serializing Objects", located at (watch for
line
wrap):

http://msdn.microsoft.com/library/de...ingobjects.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"meh" <no*************@cox.net> wrote in message
news:e8**************@TK2MSFTNGP12.phx.gbl...
I need to be able to persist a treeView to disk. I would like to save
the
node text, tag, image and selected image. I have done this using vb but
I
cant seem to translate from vb to vc#.
Can ne1 point me to documentation or samples that might help???
Thanks in advance
meh


Nov 16 '05 #3
meh,

If you provide the VB.NET code, it should not be difficult at all to
provide the equivalent C# code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"meh" <no*************@cox.net> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Thx Nicholas i did it in VB.net. I would be more than willing to share the code so as to help me understand how to convert from vb to c# dotNet. I
found a vb.net to c#.net converter on the web but the converted code does
not work.
Thanks again I will have a look at the link you provided.

meh

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
meh,

How did you do it in VB? Are you talking about VB6 or VB.NET? In
VB.NET (or C#), you will have to use the Serialization attribute, possibly in conjunction with the ISerializable interface. Check out the section of the .NET framework titled "Serializing Objects", located at (watch for
line
wrap):

http://msdn.microsoft.com/library/de...ingobjects.asp
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"meh" <no*************@cox.net> wrote in message
news:e8**************@TK2MSFTNGP12.phx.gbl...
I need to be able to persist a treeView to disk. I would like to save
the
node text, tag, image and selected image. I have done this using vb but I
cant seem to translate from vb to vc#.
Can ne1 point me to documentation or samples that might help???
Thanks in advance
meh



Nov 16 '05 #4
meh
Here is the vb code.........I keep looking at older vb.net projects to try and figure out how to teach myself C# based on my old vb code but it's been more difficult than I first thought. I'm finding that it would be better if didn't know any previous programming language.
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Runtime.Serialization.Formatters.Soap

Public Class MySerializer

<Serializable()> Structure sNode
Dim level As Integer
Dim node As String
Dim Mytag As String
Dim MyImageIndex As Integer
Dim MySelectedImageIndex As Integer

End Structure

Dim arrTreeNodes As New ArrayList()

#Region " Create Node List "

Sub CreateNodeList(ByVal node As TreeNode, ByVal fName As String)

Static level As Integer
Dim currNode As TreeNode
Dim myNode As sNode
Application.DoEvents()
myNode.level = level
myNode.node = node.Text
myNode.Mytag = node.Tag
myNode.MyImageIndex = node.ImageIndex
myNode.MySelectedImageIndex = node.SelectedImageIndex

arrTreeNodes.Add(myNode)
If node.Nodes.Count > 0 Then
level = level + 1
For Each currNode In node.Nodes
CreateNodeList(currNode, fName)
Next
level = level - 1
End If
End Sub

#End Region

#Region " Save Nodes "

Sub SaveNodesBinary(ByVal fName As String)

Dim bf As BinaryFormatter
Dim fs As FileStream
fs = File.Create(fName)
bf = New BinaryFormatter()
bf.Serialize(fs, arrTreeNodes)
fs.Close()

End Sub
'
Sub SaveNodesXML(ByVal fName As String)

Dim sf As SoapFormatter
Dim fs As FileStream
fs = File.Create(fName)
sf = New SoapFormatter()
sf.Serialize(fs, arrTreeNodes)
fs.Close()

End Sub

#End Region

#Region " Load Nodes "

Sub LoadNodesBinary(ByVal CurrTree As TreeView, ByVal fName As String)
CurrTree.Nodes.Clear()
Dim bf As BinaryFormatter
Dim fs As FileStream
fs = File.Open(fName, FileMode.Open)
bf = New BinaryFormatter()
arrTreeNodes = CType(bf.Deserialize(fs), ArrayList)
fs.Close()
showNodes(CurrTree)
End Sub
'
Sub LoadNodesXML(ByVal CurrTree As TreeView, ByVal fName As String)
CurrTree.Nodes.Clear()
Dim sf As SoapFormatter
Dim fs As FileStream
fs = File.Open(fName, FileMode.Open)
sf = New SoapFormatter()
arrTreeNodes = CType(sf.Deserialize(fs), ArrayList)
fs.Close()
showNodes(CurrTree)
End Sub

#End Region

#Region " Show Nodes "

Sub showNodes(ByVal CurrTree As TreeView)
Try
Dim o As Object
Dim currNode As TreeNode
Dim level As Integer = 0

Dim i As Integer
For i = 0 To arrTreeNodes.Count - 1
o = arrTreeNodes(i)
Dim oNode As sNode = CType(o, sNode)

If oNode.level = level Then
If currNode Is Nothing Then
currNode = CurrTree.Nodes.Add(oNode.node.ToString)
currNode.ImageIndex = (oNode.MyImageIndex.ToString)
currNode.SelectedImageIndex = (oNode.MySelectedImageIndex.ToString)
If Not oNode.Mytag = Nothing Then ' If the tag is not Null
currNode.Tag = (oNode.Mytag.ToString) ' Add the tag
End If ' End
Else
If level = 0 Then
currNode = CurrTree.Nodes.Add(oNode.node.ToString)
currNode.ImageIndex = (oNode.MyImageIndex.ToString)
currNode.SelectedImageIndex = (oNode.MySelectedImageIndex.ToString)
If Not oNode.Mytag = Nothing Then ' If the tag is not Null
currNode.Tag = (oNode.Mytag.ToString) ' Add the tag
End If ' End
Else
currNode = currNode.Parent.Nodes.Add(oNode.node.ToString) ' This line prevents Root nodes
currNode.ImageIndex = (oNode.MyImageIndex.ToString)
currNode.SelectedImageIndex = (oNode.MySelectedImageIndex.ToString)
If Not oNode.Mytag = Nothing Then ' If the tag is not Null
currNode.Tag = (oNode.Mytag.ToString) ' Add the tag
End If ' End
End If ' End
End If

Else
If oNode.level > level Then
currNode = currNode.Nodes.Add(oNode.node.ToString)
currNode.ImageIndex = (oNode.MyImageIndex.ToString)
currNode.SelectedImageIndex = (oNode.MySelectedImageIndex.ToString)
If Not oNode.Mytag = Nothing Then ' If the tag is not Null
currNode.Tag = (oNode.Mytag.ToString) ' Add the tag
End If ' End
level = oNode.level
Else
While oNode.level < level
currNode = currNode.Parent
level = level - 1
End While
If level = 0 Then
currNode = CurrTree.Nodes.Add(oNode.node.ToString)
currNode.ImageIndex = (oNode.MyImageIndex.ToString)
currNode.SelectedImageIndex = (oNode.MySelectedImageIndex.ToString)
If Not oNode.Mytag = Nothing Then ' If the tag is not Null
currNode.Tag = (oNode.Mytag.ToString) ' Add the tag
End If ' End
Else
currNode = currNode.Parent.Nodes.Add(oNode.node.ToString) ' This line prevents Root nodes
currNode.ImageIndex = (oNode.MyImageIndex.ToString)
currNode.SelectedImageIndex = (oNode.MySelectedImageIndex.ToString)
If Not oNode.Mytag = Nothing Then ' If the tag is not Null
currNode.Tag = (oNode.Mytag.ToString) ' Add the tag
End If ' End
End If
End If
End If

Application.DoEvents()
Next
CurrTree.Nodes(0).Expand()

Catch LoadException As Exception
MsgBox("Error in loading nodes! " & vbCrLf & LoadException.Message)
End Try

End Sub

#End Region

End Class
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl...
meh,

If you provide the VB.NET code, it should not be difficult at all to
provide the equivalent C# code.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"meh" <no*************@cox.net> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Thx Nicholas i did it in VB.net. I would be more than willing to share

the
code so as to help me understand how to convert from vb to c# dotNet. I
found a vb.net to c#.net converter on the web but the converted code does
not work.
Thanks again I will have a look at the link you provided.

meh

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
> meh,
>
> How did you do it in VB? Are you talking about VB6 or VB.NET? In
> VB.NET (or C#), you will have to use the Serialization attribute, possibly > in conjunction with the ISerializable interface. Check out the section of > the .NET framework titled "Serializing Objects", located at (watch for
> line
> wrap):
>
> http://msdn.microsoft.com/library/de...ingobjects.asp >
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
> "meh" <no*************@cox.net> wrote in message
> news:e8**************@TK2MSFTNGP12.phx.gbl...
>> I need to be able to persist a treeView to disk. I would like to save
>> the
>> node text, tag, image and selected image. I have done this using vb but >> I
>> cant seem to translate from vb to vc#.
>> Can ne1 point me to documentation or samples that might help???
>> Thanks in advance
>>
>>
>> meh
>>
>>
>
>



Nov 16 '05 #5

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

Similar topics

5
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
1
by: Alexandru Nedelcu | last post by:
Hi!!! I'm trying to add a UserControl created using the Page.LoadCotnrol("test.ascx") method to a Page's Control collection and the exception I get is ( the complete stack trace): ...
3
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
4
by: Ben Coats | last post by:
Hey, I'm trying to find code for an Explorer-style Directory ComboBox. (You know, it display "Desktop", "My Computer", all drives, etc., but it has a treeview control inside the combobox so that...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
5
by: david | last post by:
I do not know if there is a treeView control for web form in .NET 1.1. I know there is IE Webcontrol package which has the treeview control for ..net 1.0. I have tested it in .net 1.1 before. It...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
0
by: noneya22 | last post by:
I want to use a TreeView control as a one-level, vertical navigation menu. I'm using this control currently with a SiteMapDataSource and .sitemap file. I've written code that associates an image...
3
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I need to show a custom control in the DropDown of a Windows.Forms.ToolStripMenuItem (e.g., similar to the Font Color menu item in Word except that the control is specific to my application). I...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.