Hello,
I am desperately seeking assistance.i have spent a good 4 days on this and really want to find a solution.
I have been using Visual Studio 2008 with the sharepoint add-on.
I create a web part project and have added an additional class to use in creating and rendering a web part editor.
Within the web part editor i would like to use an SPTreeView control which renders and adds the nodes and child nodes appropriately. I declared the SPTreeView as withevents as i need to use the selected Index change event. This works fine however when the node is changed and clicked on it appears as though a post back occurs. Despite declaring all nodes to be cleared in the fill method the original nodes remain and an entire duplicate of all nodes is added to the existing ones.
I am thinking i need to determine that there is a post back.
The Code i am using is as follows.
Public Sub Fill_SiteListLibraryTreeView()
SiteListLibraryTreeView.Nodes.Clear()
Dim SiteListRootSite As SPSite = Microsoft.SharePoint.WebControls.SPControl.GetContextSite(Context).RootWeb.Site
Dim SiteListLoopSite As SPWeb
Dim ListLibrarySiteNode As TreeNode
Dim ListLibraryListNode As TreeNode
Dim ListLibraryViewNode As TreeNode
For Each SiteListLoopSite In SiteListRootSite.AllWebs
ListLibrarySiteNode = New TreeNode("Site:" & If(SiteListLoopSite.Name.Length = 0, "Root", SiteListLoopSite.Name), SiteListLoopSite.ID.ToString)
ListLibrarySiteNode.SelectAction = TreeNodeSelectAction.None
SiteListLibraryTreeView.Nodes.Add(ListLibrarySiteNode)
For Each LoopList As SPList In SiteListLoopSite.Lists
ListLibraryListNode = New TreeNode("List:" & LoopList.Title, LoopList.ID.ToString)
ListLibraryListNode.SelectAction = TreeNodeSelectAction.None
ListLibrarySiteNode.ChildNodes.Add(ListLibraryListNode)
For Each LoopView As SPView In LoopList.Views
ListLibraryViewNode = New TreeNode("View:" & LoopView.Title, LoopView.ID.ToString)
ListLibraryViewNode.SelectAction = TreeNodeSelectAction.None
ListLibraryListNode.ChildNodes.Add(ListLibraryViewNode)
Next
Next
Next
End Sub
Protected Overrides Sub CreateChildControls()
Controls.Clear()
SiteListLibraryTreeView = New SPTreeView
Controls.Add(SiteListLibraryTreeView)
Fill_SiteListLibraryTreeView()
Controls.Add(txtListViewGUID)
txtListViewGUID.Visible = True
End Sub
Public Overrides Sub RenderControl(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.Write("Custom Web Part Properties.")
writer.Write("<br/>")
writer.Write("<br/>")
writer.Write("Select the site list to view<br/>")
SiteListLibraryTreeView.RenderControl(writer)
writer.Write("<br/>")
writer.Write("<br/>")
txtListViewGUID.RenderControl(writer)
End Sub
I am desperately seeking assistance.i have spent a good 4 days on this and really want to find a solution.
I have been using Visual Studio 2008 with the sharepoint add-on.
I create a web part project and have added an additional class to use in creating and rendering a web part editor.
Within the web part editor i would like to use an SPTreeView control which renders and adds the nodes and child nodes appropriately. I declared the SPTreeView as withevents as i need to use the selected Index change event. This works fine however when the node is changed and clicked on it appears as though a post back occurs. Despite declaring all nodes to be cleared in the fill method the original nodes remain and an entire duplicate of all nodes is added to the existing ones.
I am thinking i need to determine that there is a post back.
The Code i am using is as follows.
Public Sub Fill_SiteListLibraryTreeView()
SiteListLibraryTreeView.Nodes.Clear()
Dim SiteListRootSite As SPSite = Microsoft.SharePoint.WebControls.SPControl.GetContextSite(Context).RootWeb.Site
Dim SiteListLoopSite As SPWeb
Dim ListLibrarySiteNode As TreeNode
Dim ListLibraryListNode As TreeNode
Dim ListLibraryViewNode As TreeNode
For Each SiteListLoopSite In SiteListRootSite.AllWebs
ListLibrarySiteNode = New TreeNode("Site:" & If(SiteListLoopSite.Name.Length = 0, "Root", SiteListLoopSite.Name), SiteListLoopSite.ID.ToString)
ListLibrarySiteNode.SelectAction = TreeNodeSelectAction.None
SiteListLibraryTreeView.Nodes.Add(ListLibrarySiteNode)
For Each LoopList As SPList In SiteListLoopSite.Lists
ListLibraryListNode = New TreeNode("List:" & LoopList.Title, LoopList.ID.ToString)
ListLibraryListNode.SelectAction = TreeNodeSelectAction.None
ListLibrarySiteNode.ChildNodes.Add(ListLibraryListNode)
For Each LoopView As SPView In LoopList.Views
ListLibraryViewNode = New TreeNode("View:" & LoopView.Title, LoopView.ID.ToString)
ListLibraryViewNode.SelectAction = TreeNodeSelectAction.None
ListLibraryListNode.ChildNodes.Add(ListLibraryViewNode)
Next
Next
Next
End Sub
Protected Overrides Sub CreateChildControls()
Controls.Clear()
SiteListLibraryTreeView = New SPTreeView
Controls.Add(SiteListLibraryTreeView)
Fill_SiteListLibraryTreeView()
Controls.Add(txtListViewGUID)
txtListViewGUID.Visible = True
End Sub
Public Overrides Sub RenderControl(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.Write("Custom Web Part Properties.")
writer.Write("<br/>")
writer.Write("<br/>")
writer.Write("Select the site list to view<br/>")
SiteListLibraryTreeView.RenderControl(writer)
writer.Write("<br/>")
writer.Write("<br/>")
txtListViewGUID.RenderControl(writer)
End Sub