Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Link Error:-Index was out of range. Must be non-negative and less than the size of the collection. (Read 9514 times)
Todkar
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Jun 24th, 2013
Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Feb 10th, 2014 at 9:34am
Print Post  
I am facing one issue with diagram links
I have created LinkModifying and LinkModified events. On these events I am just updating some properties of links. But sometimes I am getting error. I donít know why? And after error it stops working at all.

Index was out of range. Must be non-negative and less than the size of the collection.

I am not able to identify root cause of this issue. Will you please help me to resolve this issue?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #1 - Feb 10th, 2014 at 9:37am
Print Post  
Check if you aren't changing SegmentCount during LinkModifying event. That will cause index-out-of-bounds exception if the link remains with fewer control points than the index of currently dragged point.

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


I Love MindFusion!

Posts: 20
Joined: Jun 24th, 2013
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #2 - Feb 10th, 2014 at 10:47am
Print Post  
Thanks for your swift reply
Below things i am doing on modifying and modified
1. changeing link.Shape
2. changing the start point and end point of line as link moved and points need to be updated.
3. link.UpdateFromPoints();
4. Reroute the link

my question is that Why it throwing such error? what is the root cause?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #3 - Feb 10th, 2014 at 12:05pm
Print Post  
Both routing and changing link.Shape (e.g. Bezier to Polyline) could reduce number of points and cause exception after LinkModifying returns. The root cause is that the control keeps an integer index of current control point being dragged, and if you remove points the index gets incorrect.
  
Back to top
 
IP Logged
 
Todkar
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Jun 24th, 2013
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #4 - Feb 11th, 2014 at 9:01am
Print Post  
Hi Thanks for your reply.

I am trying to modify the code as per your suggestion.

This issue occurs with one another scenario as below

When I select the link and try to move start / end point and mouse moves outside the diagram area, and release the mouse. in that case it occurs.

How can I identify the mouse is released outside or inside the diagram area, do we have any specific event for that? or please suggest me some work around to overcome this issue. even i reset the diagram after doing above steps, diagram get hang. selection of node / link is not happening


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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #5 - Feb 11th, 2014 at 1:25pm
Print Post  
Quote:
When I select the link and try to move start / end point and mouse moves outside the diagram area, and release the mouse. in that case it occurs.


What happens then, the same index out of range exception? When you release the mouse button, the diagram raises LinkModifying for one last time, are you still setting link's Shape or rerouting from it? We consider LinkModifying a validation event, and expect you'd only set e.Cancel or call e.CancelDrag(). You might still be able to modify links from it - try setting diagram.Interaction.AdjustmentHandle.Index to the largest index of link.ControlPoints, if you detect it's no longer valid after removing points.
  
Back to top
 
IP Logged
 
Todkar
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Jun 24th, 2013
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #6 - Feb 11th, 2014 at 1:55pm
Print Post  

Quote:
When I select the link and try to move start / end point and  mouse moves outside the diagram area, and release the mouse. in that case it occurs.


Diagram is no responding more, I have to logot to my application.

I check this in debug mode also its not throwing exception / error.

where should I set diagram.Interaction.AdjustmentHandle.Index

Thanks

  
Back to top
 
IP Logged
 
Todkar
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Jun 24th, 2013
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #7 - Feb 11th, 2014 at 2:23pm
Print Post  

I have custom Behavirour class as below

public class MyBehavirour : LinkShapesBehavior
{
      public MyBehavirour(Diagram diagram)
            : base(diagram)
        {
        }

      protected override void OnMouseMove(MouseEventArgs e)
      {
           base.OnMouseMove(e);
       }

protected override void OnMouseUp(MouseButtonEventArgs e)

protected override bool OnMouseDown(MouseButtonEventArgs e)

}

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #8 - Feb 11th, 2014 at 6:32pm
Print Post  
Quote:
Diagram is no responding more, I have to logot to my application.
I have custom Behavirour class as below


That's not compilable code, please copy the full class or better attach a test project reproducing that.

Quote:
where should I set diagram.Interaction.AdjustmentHandle.Index


In your LinkModifying handler when you remove control points, even if indirectly by changing Shape or calling Route.
  
Back to top
 
IP Logged
 
Todkar
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Jun 24th, 2013
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #9 - Feb 12th, 2014 at 7:40am
Print Post  
it will take much time to create test project, i will try for sure and share with you in couple of days. till time it would be good if i will get some answers to below questions from you.

1. in my scenario, if I drag start point of link and drop it outside the Diagram, in that case LinkModifying is not triggered. see the attached screen shot  "ScreenShot_1.jpg"

2. If i need to change the shape and rout the link on Moving of the link start point, which is right event to do that?

Thanks,
  

ScreenShot_1.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Link Error:-Index was out of range. Must be non-negative and less than the size of the collection.
Reply #10 - Feb 13th, 2014 at 11:28am
Print Post  
Quote:
1. in my scenario, if I drag start point of link and drop it outside the Diagram, in that case LinkModifying is not triggered. see the attached screen shot  "ScreenShot_1.jpg"


LinkModifying won't be raised if AllowUnconnectedLinks is disabled and there is no node at the drop location. That should not prevent you from drawing on the diagram anymore though. Are you calling base.OnMouseUp from your custom behavior class override? It might not complete interaction correctly otherwise.

Quote:
2. If i need to change the shape and rout the link on Moving of the link start point, which is right event to do that?


That's not something the control would expect you to do. The closest event you can use is LinkModifying; as above you might need to modify diagram.Interaction.AdjustmentHandle.Index if the link remain with less points than that index.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint