Welcome Guest Search | Active Topics | Sign In | Register

SlideMenu FindItem Options
quirtep
Posted: Wednesday, September 12, 2007 8:38:38 AM
Rank: Advanced Member
Groups: Member

Joined: 9/6/2007
Posts: 133
Will you please provide an example of FindItem? I cannot seem to find a sample in the documentation.

What I want to do is this: Within SlideMenu1_ItemClick, I want to find the currently selected item, and then set EnsureVisible to true for this item.

Edit: I am not sure "EnsureVisible" is what I'm after. I need for the parent item to be expanded if a sub-item is selected, and I would prefer to handle it server side.

Thanks.
eo_support
Posted: Wednesday, September 12, 2007 8:54:54 AM
Rank: Administration
Groups: Administration

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

Thanks for posting the question here. EnsureVisible won't do the trick. To have the parent item expanded, you must set the parent item's Selected and Expanded to true. EnsureVisible is a method on the TreeNode. It has nothing to do with the slide menu.

FindItem on the hand is a method on NavigationItem, which is base class of both MenuItem and TreeNode, so it works on both. For an example of this function, you can look at default.aspx.cs/.vb in the demo project. That page uses this method. The sample calls this method on the TreeView, but it would be the same to be used on a menu.

Thanks
quirtep
Posted: Wednesday, September 12, 2007 9:09:48 AM
Rank: Advanced Member
Groups: Member

Joined: 9/6/2007
Posts: 133
Thanks. It doesn't appear that FindItem will do the trick since it relies on path and I am not using NavigateUrl but instead use EO.Web.CallbackEventArgs e to determine the item that was clicked.

I tried this within SlideMenu1_ItemClick:

---
e.MenuItem.Selected = true;
e.MenuItem.ParentItem.Selected = true;
e.MenuItem.ParentItem.Expanded = true;
---

It works so long as I am only using sub-items for navigation, but as soon as a top-level item with a value is clicked, that item becomes selected even on subsequent clicks. How can I ensure that sub-items are visible when there is a postback?
eo_support
Posted: Wednesday, September 12, 2007 9:22:58 AM
Rank: Administration
Groups: Administration

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

I am not sure whether I understood you correctly --- please correct me if I got it wrong. My understanding that you want to keep a single "Selected Path". So if you have items like this:

* Parent 1
* Parent 2
----- Child 1

When the user clicks "Child 1", the selected path will be "Parent 2 -> Child 1", if user then click "Parent 1", the selected path should be "Parent 1". If then user click "Parent 2" again, then the selected Path should be "Parent 2". However the problem at here is at this moment, "Parent 1" is still selected.

In order to avoid this, the easiest way is when you set e.MenuItem.Selected to true, you also set all its siblings to false. For example:

Code: C#
void function SelectSingleItem(EO.Web.MenuItem item)
{
    foreach (EO.Web.MenuItem childItem in item.ParentItem.SubMenu.Items)
    {
        item.Selected = childItem == item;
        item.Expanded = childItem == item;
    }
}


Thanks
quirtep
Posted: Wednesday, September 12, 2007 9:33:08 AM
Rank: Advanced Member
Groups: Member

Joined: 9/6/2007
Posts: 133
Well, your sample didn't quite do it - it still acted as described after a top-level item was clicked. But - this slightly modified alternative did the trick:

protected void SlideMenu1_ItemClick(object sender, EO.Web.NavigationItemEventArgs e)
{
foreach (EO.Web.MenuItem item in SlideMenu1.Items)
{
item.Selected = false;
item.Expanded = false;
}
e.MenuItem.Selected = true;
e.MenuItem.ParentItem.Expanded = true;
}

Thanks for the help - and showing how to simply clear all selected items so that I could then just manually select and expand as needed.
eo_support
Posted: Wednesday, September 12, 2007 9:36:22 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Ah. I spotted the error in my code by comparing with yours. It has been corrected now. :) Glad to hear that it works for you!
eo_support
Posted: Wednesday, September 12, 2007 9:39:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
eo_support wrote:
Ah. I spotted the error in my code by comparing with yours. It has been corrected now. :) Glad to hear that it works for you!


Never mind the previous post. I spoke too soon. What matters is that your code is working for you. :)


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.