how to save TreeView State
-
28 Şubat 2012 Salı 11:14
Hello all
is it possible to save the state of a treeview??
I may or delete items in treeview
later i want to restore the same with the state i saved before..
thanks in advance.
Tüm Yanıtlar
-
28 Şubat 2012 Salı 17:13
Hi sadikvt,
check below sample to save TreeViewState
http://blog.binaryocean.com/PermaLink,guid,23808645-43b5-4e2a-afb1-53dc8da35636.aspx
Regads
Fazal
-
29 Şubat 2012 Çarşamba 15:20
Hello all
is it possible to save the state of a treeview??
Yes! In fact there is a nice handy code example that will show you exactly how this is done. Download it off the MSDN and walk through the code. It should have everything you need:
Maintain ASP.NET TreeView State:
http://code.msdn.microsoft.com/CSASPNETMaintainTreeViewSta-c7673683Thank you,
- Yanıt Olarak Öneren atconway 29 Şubat 2012 Çarşamba 15:21
- Yanıt Olarak İşaretleyen Mike FengMicrosoft Contingent Staff, Moderator 07 Mart 2012 Çarşamba 12:31
-
01 Mart 2012 Perşembe 06:27Moderatör
Hi Sadikvt,
Welcome to the MSDN Forum.
Does your application is asp.net one? If so, atconway's suggest should be helpful.
If your application is a winform one, you can try to save your nodes into a XML file. And populate the treeview with your stored xml file node by the following code snippet:
Private Sub AddTreeViewChildNodes(ByVal parent_nodes As TreeNodeCollection, ByVal xml_node As XmlNode) For Each child_node As XmlNode In xml_node.ChildNodes Dim new_node As TreeNode = parent_nodes.Add(child_node.Name) 'set your tag here If child_node.Attributes("Tag") IsNot Nothing Then new_node.Tag = child_node.Attributes("Tag").Value Else new_node.Tag = "" End If AddTreeViewChildNodes(new_node.Nodes, child_node) If new_node.Nodes.Count = 0 Then new_node.EnsureVisible() Next child_node End Sub Private Sub SaveTreeViewChildNodes(ByVal parent_nodes As TreeNodeCollection, ByVal xml_node As XmlElement) For Each child_node As TreeNode In parent_nodes Dim new_node As XmlElement Dim doc As New XmlDocument new_node = doc.CreateElement(XmlNodeType.Element, child_node.Name, "") 'set your tag here new_node.SetAttribute("Tag", child_node.Tag) xml_node.AppendChild(new_node) SaveTreeViewChildNodes(child_node.Nodes, new_node) Next child_node End Sub
I hope this will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Yanıt Olarak İşaretleyen Mike FengMicrosoft Contingent Staff, Moderator 07 Mart 2012 Çarşamba 12:31