Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to remove all arrows ? (Read 2957 times)
isteele
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: Mar 12th, 2007
How to remove all arrows ?
Aug 30th, 2007 at 3:11pm
Print Post  
Hi,

This might seem like an odd question, but how can I programmatically remove all the existing arrows in a chart ?

I tried calling fc.Arrows.Clear(), but even though the Arrows.count value was set to zero the arrows were still displayed even after calling Refresh().

Furthermore, if I subsequently tried to manually remove one of the arrows after calling the Clear() method the following Argument Exception was thrown

"Cannot remove the specified item because it was not found in the specified Collection."

Thanks in advance,


Ian.

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to remove all arrows ?
Reply #1 - Aug 30th, 2007 at 3:17pm
Print Post  
Hi,

You should delete the arrows one by one:

while (fc.Arrows.Count > 0)
  fc.DeleteObject(fc.Arrows[0]);

Calling diagram.Links.Clear() should work fine in version 5 of the control.

Stoyan
  
Back to top
 
IP Logged
 
isteele
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: Mar 12th, 2007
Re: How to remove all arrows ?
Reply #2 - Aug 30th, 2007 at 3:34pm
Print Post  
Hi Stoyan,

Thanks for the quick reply!

I tried the code you suggested but it went into an invariant state as Arrows.count was decremented once, but never decremented thereafter (seems like the Arrows collection is a little bit buggy - looking forwards to V5!).

I got around the problem but using a local variable set to the initial Arrows.count value and decrementing it and it all worked fine:

           int aa = fc.Arrows.Count;

           while (aa > 0)
           {
               fc.DeleteObject(fc.Arrows[0]);
               aa--;
           }


Best regards,


Ian.
  
Back to top
 
IP Logged
 
isteele
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: Mar 12th, 2007
Re: How to remove all arrows ?
Reply #3 - Aug 30th, 2007 at 3:55pm
Print Post  
Hi again,

I said previously that it was now working - my mistake, it isn't! Smiley

Even after using a local variable as a count when removing arrows the Arrow.count is still non-zero.

In the test I am using the Arrow.count value is set to 7 immediately after the while loop (initially it was 10), example...

           int aa = fc.Arrows.Count;  // aa == 10
           
           while (aa > 0)
           {
               fc.DeleteObject(fc.Arrows[0]);
               aa--;
           }

           aa = fc.Arrows.Count;  // aa = 7

Interestingly when the diagram is displayed there are in fact *4* arrows displayed.  I verified that there were no overlayed arrows by manually deleting them (without any exceptions this time though!).

Something very odd is happening here.

Can you suggest anything ?

Best regards,


Ian.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to remove all arrows ?
Reply #4 - Aug 30th, 2007 at 4:05pm
Print Post  
For some reason some arrows might be referenced more than once from the collection. Check if you are not calling Add and adding an arrow more than once? Or by some chance adding new arrows from the ArrowDeleted event?

Stoyan
  
Back to top
 
IP Logged
 
isteele
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 6
Joined: Mar 12th, 2007
Re: How to remove all arrows ?
Reply #5 - Aug 30th, 2007 at 4:14pm
Print Post  
Hi yet again,

I really have solved the problem this time!...

I was adding the arrows using fc.CreateArrow(), but there was an old bit of code that was also adding the arrows directly to the collection using fc.Arrows.Add().  Removed the latter call and all works swimmingly now!

Thanks for you help, Stoyan.

Best regards,


Ian.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint