Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Deleting last row in TableNode with AnchorPattern (Read 2105 times)
GlitchEnzo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Aug 4th, 2010
Deleting last row in TableNode with AnchorPattern
Aug 4th, 2010 at 11:00pm
Print Post  
I'm using a TableNode with an AnchorPattern specified on each row. I want to be able to add/remove rows from the TableNode dynamically. This works well except when I try to delete the last row in the TableNode. It appears to work fine, but the next time the TableNode is moused-over, an exception is thrown.

Here's the exception stack trace:
Code
Select All
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.get_Item(Int32 index)
   at MindFusion.Diagramming.Wpf.TableNode.CellCollection.get_Item(Int32 index)
   at MindFusion.Diagramming.Wpf.TableNode.get_Item(Int32 col, Int32 row)
   at MindFusion.Diagramming.Wpf.TableNode.x3d2277a3b84b3698(AnchorPoint x1bf64e6273c3575c, Visibility x9b4602d5e4f04fcb)
   at MindFusion.Diagramming.Wpf.DiagramNode.x3d2277a3b84b3698(DiagramNode x8d5eca828b99d00c)
   at MindFusion.Diagramming.Wpf.DiagramNode.x3d2277a3b84b3698()
   at MindFusion.Diagramming.Wpf.Diagram.x92bb101faf551658(DiagramNode xda5bf54deb817e37)
   at MindFusion.Diagramming.Wpf.Diagram.xc9ce7799411b196f(Point x70c02b32ea858ee7)
   at MindFusion.Diagramming.Wpf.Diagram.OnPreviewMouseMove(MouseEventArgs e)
 



Here is the simple code to replicate this problem:
Code
Select All
AnchorPattern anchorPattern = new AnchorPattern(
new[]
{
   new AnchorPoint(50, 50, true, false, Brushes.Green, 0){MarkStyle = MarkStyle.Custom},
});

// defaults to 4 rows and 2 columns
TableNode tableNode = new TableNode();

tableNode.Rows[0].AnchorPattern = anchorPattern;
tableNode.Rows[1].AnchorPattern = anchorPattern;
tableNode.Rows[2].AnchorPattern = anchorPattern;
tableNode.Rows[3].AnchorPattern = anchorPattern;

Diagram.Nodes.Add(tableNode);

tableNode.DeleteRow(3);
 



I've noticed that the exception only occurs when using an AnchorPattern that uses a specific column in the row. If I set the Column property back to the default value of -1 right before deleting, the exception is not thrown.

Like this:
Code
Select All
tableNode.Rows[3].AnchorPattern.Points[0].Column = -1;
tableNode.DeleteRow(3);
 



That is a bad hack though, as we have different AnchorPatterns that could be used with varying numbers of points. Plus other odd things start happening with the adding/removing of other rows.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting last row in TableNode with AnchorPatt
Reply #1 - Aug 5th, 2010 at 6:07am
Print Post  
Our bad, this build should fix that:
https://www.mindfusion.eu/_beta/wpfdiag241.zip

What are the other odd things happening?
  
Back to top
 
IP Logged
 
GlitchEnzo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Aug 4th, 2010
Re: Deleting last row in TableNode with AnchorPatt
Reply #2 - Aug 5th, 2010 at 6:37pm
Print Post  
Thanks that fixed that specific issue. However that same exception is still being thrown if I try to resize the TableNode after deleting a row.

Here is the slightly tweaked code showing this problem:
Code
Select All
AnchorPattern anchorPattern = new AnchorPattern(
new[]
{
    new AnchorPoint(50, 50, true, false, Brushes.Green, 0){MarkStyle = MarkStyle.Custom},
});

// defaults to 4 rows and 2 columns
TableNode tableNode = new TableNode();

tableNode.Rows[0].AnchorPattern = anchorPattern;
tableNode.Rows[1].AnchorPattern = anchorPattern;
tableNode.Rows[2].AnchorPattern = anchorPattern;
tableNode.Rows[3].AnchorPattern = anchorPattern;

Diagram.Nodes.Add(tableNode);

tableNode.MouseDown += delegate
{
    tableNode.DeleteRow(2);
    tableNode.Bounds = new Rect(50, 50, 200, 150);
};
 



As soon as the Bounds property is set, it causes the exception to be thrown.

The same problem occurs if the Resize method is called instead of setting the Bounds.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting last row in TableNode with AnchorPatt
Reply #3 - Aug 6th, 2010 at 9:44am
Print Post  
TableNodes did not update some row indices associated with anchor points until the next WPF arrange stage after deleting the rows. It might be possible to force the arrange pass by calling UpdateLayout as work-around, but this version should fix that anyway by immediately updating the row indices when deleting:

https://mindfusion.eu/_beta/wpfdiag241_apindex.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint