Welcome Guest Search | Active Topics | Sign In | Register

TreeView "Object Not Found" Options
Bill Murray
Posted: Monday, December 13, 2010 1:20:05 AM

Rank: Newbie
Groups: Member

Joined: 11/6/2010
Posts: 7
Here is my code
Quote:

<mms:CallbackPanel ID="callbackPanel" runat="server" Height="150px" Width="230px">
<mms:TreeView ID="TreeView1" runat="server" Width="230px" ControlSkinID="None" AutoWrap="True" ViewStateMode="Enabled" AutoSelectSource="ItemClick" AllowMultiSelect="false" AllowDragDrop="false" AllowDragReordering="false" ClientSideOnContextMenu="ShowContextMenu" OnItemPopulate="TreeView1_ItemPopulate" RaisesServerEvent="true">
<LookNodes>
<mms:TreeNode ImageUrl="00030301" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;"
CollapsedImageUrl="00030301" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"
ExpandedImageUrl="00030302" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;"></mms:TreeNode>
</LookNodes>
<TopGroup Style-CssText="color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;">
<Nodes>
<mms:TreeNode Text="Pages" ItemID="0"></mms:TreeNode>
</Nodes>
</TopGroup>
</mms:TreeView>
<mms:ContextMenu id="Menu1" Width="144px" runat="server" ControlSkinID="None" RaisesServerEvent="true" ClientSideOnItemClick="ContextClicked">
<TopGroup Style-CssText="cursor:hand;font-family:Verdana;font-size:11px;">
<Items>
<mms:MenuItem Text-Html="Add a Page"></mms:MenuItem>
<mms:MenuItem Text-Html="Add a Folder"></mms:MenuItem>
<mms:MenuItem Text-Html="Delete"></mms:MenuItem>
<mms:MenuItem IsSeparator="True"></mms:MenuItem>
<mms:MenuItem Text-Html="Properties"></mms:MenuItem>
</Items>
</TopGroup>
<LookItems>
<mms:MenuItem IsSeparator="True" ItemID="_Separator" NormalStyle-CssText="background-color:#E0E0E0;height:1px;width:1px;"></mms:MenuItem>
<mms:MenuItem HoverStyle-CssText="color:#F7B00A;padding-left:5px;padding-right:5px;" ItemID="_Default" NormalStyle-CssText="padding-left:5px;padding-right:5px;">
<SubMenu ExpandEffect-Type="GlideTopToBottom" Style-CssText="border-right: #e0e0e0 1px solid; padding-right: 3px; border-top: #e0e0e0 1px solid; padding-left: 3px; font-size: 12px; padding-bottom: 3px; border-left: #e0e0e0 1px solid; cursor: hand; color: #606060; padding-top: 3px; border-bottom: #e0e0e0 1px solid; font-family: arial; background-color: #f7f8f9" CollapseEffect-Type="GlideTopToBottom" OffsetX="3" ShadowDepth="0" OffsetY="-4" ItemSpacing="5"></SubMenu>
</mms:MenuItem>
</LookItems>
</mms:ContextMenu>
</mms:CallbackPanel>


and my code-behind:

Quote:

Protected Sub Menu1_ItemClick(ByVal Sender As System.Object, ByVal e As NavigationItemEventArgs) Handles Menu1.ItemClick
Dim ItemSelected As String = TreeView1.ContextNode.ItemID.ToString


I have worked with this for over 8 hours and I think I am just not getting it ... can someone please just give me an example or help by fixing the code!

Here is what I want to accomplish...A user right clicks (context menu) on the tree view and selects, "Add Folder"
I just want to get that selected folders ItemID (or value or anything I can use to identify it)

No matter what I do - I am getting a "Object Not Found"

I have gone through all 7 pages of related questions ... and I went through the samples ... and the documentation ... have concluded that I am dumb! This seems straightforward and intuitive - but I cannot find an example that makes it work
:(

I really appreciate any help ... thanks


eo_support
Posted: Monday, December 13, 2010 8:05:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Your code looks fine. The only thing you want to check is to make sure that each item indeed has an ItemID. If it has not been set, then ItemID will be null and will give you "Object Not Found" error when you call ToString on it.

Thanks
Bill Murray
Posted: Saturday, December 18, 2010 2:34:39 PM

Rank: Newbie
Groups: Member

Joined: 11/6/2010
Posts: 7
Got it... still having a problem:
1. I am using populate on demand...

2. When I create a node under my ItemID=0 (see .aspx "<eo:TreeNode Text="Pages" ItemID="0" Value="0,0,F"></eo:TreeNode>") getting the "nodeItem" (see Menu1_ItemClick event) works just fine.

3. When I attempt to create sub-nodes however getting the "nodeItem" throws the same exception (object not found).

4. Note that in both ("PopulateFirstLevel" and "GetSubNodes") - I am adding both a ".value" and a ".ItemID" (referring to the previous response).

Question: Why is that I am unable to retrieve the selected contextnode value from sub nodes but I am on their parents? and what do I need to do to get these values and stop throwing exceptions



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateFirstLevel()
Else
SelectedNode = ViewState("SelectedNode")
SelectedOrder = ViewState("SelectedOrder")
SelectedType = ViewState("SelectedType")
End If
End Sub

Protected Sub Menu1_ItemClick(ByVal sender As Object, ByVal e As NavigationItemEventArgs)
Dim nodeItem As TreeNode = TreeView1.ContextNode 'Throws error for all subnodes
...

End Sub
Protected Sub TreeView1_ItemPopulate(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs)

'Get the parent node
Dim parentNode As EO.Web.TreeNode = CType(e.NavigationItem, EO.Web.TreeNode)
GetSubNodes(parentNode)
End Sub

Private Sub GetSubNodes(ByVal ParentNode As TreeNode)
Dim n As MMS.Content.Nodes = New MMS.Content.Nodes(User.Identity.Name)
Dim dt As DataTable = Nothing
Dim ParentNodeID As Integer = 0

Try
ParentNodeID = CInt(ParentNode.ItemID)
Catch ex As Exception
End Try

If ParentNodeID > 0 Then
'NodeID, ParentNodeID, DisplayOrder, ItemName, ItemType
dt = n.getFolderData(MMS.Content.Nodes.ObjectType.Site, ParentNodeID)
For Each dr As DataRow In dt.Rows
Dim node As TreeNode = New TreeNode(dr(3))
node.ItemID = dr(0).ToString
node.Value = dr(0).ToString & "," & dr(2).ToString & "," + dr(4).ToString
If dr(4) = "P" Then
node.ImageUrl = "00030203"
node.PopulateOnDemand = False
Else
node.PopulateOnDemand = True
End If
ParentNode.SubGroup.Nodes.Add(node)
Next
ParentNode.ExpandPath()
End If
End Sub

Private Sub PopulateFirstLevel()
Dim n As MMS.Content.Nodes = New MMS.Content.Nodes(User.Identity.Name)
Dim dt As DataTable = Nothing

dt = n.getFolderData(MMS.Content.Nodes.ObjectType.Site)

'NodeID, ParentNodeID, DisplayOrder, ItemName, ItemType
For Each dr As DataRow In dt.Rows
Dim node As TreeNode = New TreeNode(dr(3))
node.ItemID = dr(0).ToString
node.Value = dr(0).ToString & "," & dr(2).ToString & "," + dr(4).ToString
If dr(4) = "P" Then
node.ImageUrl = "00030203"
node.PopulateOnDemand = False
Else
node.PopulateOnDemand = True
End If
TreeView1.TopGroup.Nodes(0).ChildNodes.Add(node)
Next
TreeView1.ExpandAll()
End Sub

.aspx code: everything between my form tags:

<script type="text/javascript">
function ShowContextMenu(e, treeView, node) {
var menu = eo_GetObject("<%=Menu1.ClientID%>");
eo_ShowContextMenu(e, "<%=Menu1.ClientID%>");
return true;
}
function ContextClicked(evt, eventInfo) {
eo_Callback('<%=callbackPanel.ClientID%>', eventInfo.getItem().getValue());
return true;
}
</script>
<eo:ScriptEvent ID="ScriptEvent1" runat="server"></eo:ScriptEvent>
<eo:CallbackPanel ID="callbackPanel" runat="server" Height="150px" Width="230px" OnExecute="treePanel_Execute">
<eo:TreeView ID="TreeView1" runat="server" Width="230px" ViewStateMode="Enabled" ControlSkinID="None" AutoWrap="True" AutoSelectSource="ItemClick" OnItemPopulate="TreeView1_ItemPopulate" ClientSideOnContextMenu="ShowContextMenu" RaisesServerEvent="true">
<LookNodes>
<eo:TreeNode ImageUrl="00030301" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;"
CollapsedImageUrl="00030301" ItemID="_Default" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none"
ExpandedImageUrl="00030302" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;"></eo:TreeNode>
</LookNodes>
<TopGroup Style-CssText="color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;">
<Nodes>
<eo:TreeNode Text="Pages" ItemID="0" Value="0,0,F"></eo:TreeNode>
</Nodes>
</TopGroup>
</eo:TreeView>
</eo:CallbackPanel>
<eo:ContextMenu id="Menu1" Width="144px" runat="server" ControlSkinID="None" RaisesServerEvent="true" OnItemClick="Menu1_ItemClick">
<TopGroup Style-CssText="cursor:hand;font-family:Verdana;font-size:11px;">
<Items>
<eo:MenuItem Text-Html="Add a Page"></eo:MenuItem>
<eo:MenuItem Text-Html="Add a Folder"></eo:MenuItem>
<eo:MenuItem Text-Html="Delete"></eo:MenuItem>
<eo:MenuItem IsSeparator="True"></eo:MenuItem>
<eo:MenuItem Text-Html="Properties"></eo:MenuItem>
</Items>
</TopGroup>
<LookItems>
<eo:MenuItem IsSeparator="True" ItemID="_Separator" NormalStyle-CssText="background-color:#E0E0E0;height:1px;width:1px;"></eo:MenuItem>
<eo:MenuItem HoverStyle-CssText="color:#F7B00A;padding-left:5px;padding-right:5px;" ItemID="_Default" NormalStyle-CssText="padding-left:5px;padding-right:5px;">
<SubMenu ExpandEffect-Type="GlideTopToBottom" Style-CssText="border-right: #e0e0e0 1px solid; padding-right: 3px; border-top: #e0e0e0 1px solid; padding-left: 3px; font-size: 12px; padding-bottom: 3px; border-left: #e0e0e0 1px solid; cursor: hand; color: #606060; padding-top: 3px; border-bottom: #e0e0e0 1px solid; font-family: arial; background-color: #f7f8f9" CollapseEffect-Type="GlideTopToBottom" OffsetX="3" ShadowDepth="0" OffsetY="-4" ItemSpacing="5"></SubMenu>
</eo:MenuItem>
</LookItems>
</eo:ContextMenu>

eo_support
Posted: Sunday, December 19, 2010 10:48:07 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

This behavior is by design. When you use PopulateOnDemand, the TreeView only creates an "island" node that represents the node that you wish to populate. It does not recreate the whole tree for performance considerations. As a result, you will not be able to get the parent node. If you need to get parent node data, you would usually get it from your database based on the current node information.

Thanks!
Bill Murray
Posted: Sunday, December 19, 2010 12:12:20 PM

Rank: Newbie
Groups: Member

Joined: 11/6/2010
Posts: 7
I am confused.

I just wanted a treeview that populates on demand.

The only objective I still have is to be able to right click on any node within my tree and be able to know what the ItemID is for that node.

Just so I am clear,
I have told you that this behavior works fine at the root node - but when I right-click on a sub-node (something beneath the "populate first level" - you are telling me that, by design, I have no way of getting that selected sub-node's ItemID?


eo_support
Posted: Sunday, December 19, 2010 1:23:16 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Sorry I misunderstood your question. The restriction we mentioned is that you can not access parent node inside your PopulateOnDemand handler. Inside your PopulateOnDemand handler, the only node you have access with is e.NavigationItem. You can create child nodes for that node, but you can not access its parent node.

This is however unrelated to your scenario. We are not aware of anything on the TreeView that can cause TreeView1.ContextMenu to throw an error. So I do not know exactly what you meant by "TreeView1.ContextNode 'Throws error for all subnodes". Accessing "TreeView1.ContextNode" should not fail as long as TreeView1 is valid.

If the problem continues to occur, you can try to isolate the problem into a test page and post the test page. Please make sure the test page runs independently and also only contains code needed to reproduce the problem (this means all your DB related code needs to be removed). Once we have that we will try to run it here and see what we can find. Please keep in mind that we do not review user code for possible user code/logic errors. So if there is a logic error, we will tell you the direct reason why it fails, but we will not be able to help you analyze or fix the logic error that caused it.

Thanks!
Bill Murray
Posted: Sunday, December 19, 2010 3:09:42 PM

Rank: Newbie
Groups: Member

Joined: 11/6/2010
Posts: 7
Here is a link to a complete sample project that should completely illustrate the issue:
http://tinyurl.com/eoTreeView

Note, also there is a PDF "walkthrough" with screen shots that illustrates the behavior exactly.


Bill
eo_support
Posted: Sunday, December 19, 2010 4:52:21 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We looked into your code and the reason is because you only repopulated the first level when the page is not posted back. When the page is not posted back, the page is reconstructed from ground up and you will need to repopulate the whole tree, not just the first level.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.