Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Remembering Collapsed/Expanded States (Read 3042 times)
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Remembering Collapsed/Expanded States
Mar 4th, 2010 at 10:06am
Print Post  
Is there any way to remember the expanded/collapsed state of a diagram node when a parent of that node is collapsed?  For example, if I have A -> B -> C -> D then I collapse C, and then collapse A, when I expand A, I would like C to still be collapsed.

I was thinking about doing this manually, but when A is collapsed, is the state of C remembered?  It would be great to have an option to do this automatically.

-Ben
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Remembering Collapsed/Expanded States
Reply #1 - Mar 4th, 2010 at 10:40am
Print Post  
The expanded states of items are not remembered. It should be easy to implement that by setting ExpandButtonAction to Custom and handling The ExpandButtonClicked event. The handler can store the Visible property value of each descendant of e.Node in a Dictionary<DiagramItem, bool> before calling e.Node.Collapse, or respectively restore Visible of each descendant after e.Node.Expand. You will also have to call the SetExpandedFlag method to set the +/- button state.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Remembering Collapsed/Expanded States
Reply #2 - Mar 4th, 2010 at 7:05pm
Print Post  
Thanks for the information.

I have some very simple code and already running into two problems. With the following:

Code
Select All
        public static void diagram_ExpandButtonClicked(object sender, NodeEventArgs e)
        {
            if (e.Node.Expanded)
            {
                e.Node.Collapse();
            }
            else
            {
                e.Node.Expand();
            }
        }
 



For some reason, e.Node.Expanded always returns false. So I changed the condition to e.Node.OutgoingLinks[0].Destination.Visible instead and this works, but when I click the +/- button, the button itself changes state but nothing else happens. When I click it again, the +/- button stays the same and the node changes state. Could you explain what is going on internally?

Thanks,
Ben
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Remembering Collapsed/Expanded States
Reply #3 - Mar 4th, 2010 at 7:55pm
Print Post  
It seems the problem is that the Expanded flag is toggled before raising the event, and you get the value that the node and its children should be after the button is clicked. However then the standard Expand / Collapse methods do not work because the recursion stops when it reaches a node with Expanded flag of the same value. You could work around this as below:

Code
Select All
Debug.WriteLine(e.Node.Expanded);
if (e.Node.Expanded)
{
	e.Node.SetExpandedFlag(false);
	e.Node.Expanded = true;
}
else
{
	e.Node.SetExpandedFlag(true);
	e.Node.Expanded = false;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Remembering Collapsed/Expanded States
Reply #4 - Mar 5th, 2010 at 5:09am
Print Post  
I wanted to share my solution to this in case anyone is interested. It turned out to be amazingly simple! I simply don't change the expanded flag when collapsing the nodes:

Code
Select All
        public static void diagram_ExpandButtonClicked(object sender, NodeEventArgs e)
        {
            // Note: e.Node.Expanded is set before entering this handler
            if (e.Node.Expanded)
                ExpandNode(e.Node);
            else
                CollapseNode(e.Node);
        }

        private static void CollapseNode(DiagramNode node)
        {
            foreach (DiagramLink link in node.OutgoingLinks)
            {
                link.Visible = false;
                link.Destination.Visible = false;
                CollapseNode(link.Destination);
            }
        }

        private static void ExpandNode(DiagramNode node)
        {
            foreach (DiagramLink link in node.OutgoingLinks)
            {
                link.Visible = true;
                link.Destination.Visible = true;
                if (link.Destination.Expanded)
                    ExpandNode(link.Destination);
            }
        }
 


This will only expand up to a node that was previously collapsed.

-Ben
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint