Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Removing Group not working (Read 3936 times)
srinivas
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 41
Joined: Jul 27th, 2010
Removing Group not working
Aug 18th, 2010 at 2:27pm
Print Post  
Hi,

I am getting the error saying "Cannot remove the specified item because it was not found in the specified collection".

Please let me know how to delete multiple items selected in the diagram. It is working find for all other nodes except that if I select a Group and any other node in combination I am getting the above error.

I have DelKeyAction set to MindFusion.Diagramming.DelKeyAction.DeleteSelectedItems. I am clicking on Del key after selecting two nodes.

I am using latest MindFusion.Diagramming control version 5.3.5.

Plese suggest a solution, thanks in advance.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Removing Group not working
Reply #1 - Aug 18th, 2010 at 3:24pm
Print Post  
Hi,

Are you handling the NodeDeleted event?

Regards,
Stoyan
  
Back to top
 
IP Logged
 
srinivas
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 41
Joined: Jul 27th, 2010
Re: Removing Group not working
Reply #2 - Aug 19th, 2010 at 5:22am
Print Post  
NodeDeleted event is not handled in the code, removal of nodes is done in Form.ctxtMenuDelete.Click event, where the selected items are iterated and are getting removed from Diagram.Items collection.

Is this the right way of removing diagram items?

This was working fine with all other nodes but not working for the newly added DiagramGroup.

We have upgraded to use Group and I have a class DiagramGroup with a ShapeNode and Group objects and using this DiagramGroup class to draw the group and attach the nodes.

Actual issue is that when I add group and a node to the diagram and selecting both and clicking Delete button is throwing the error I mentioned in my earlier post.

Please le me know how to handle this correctly.


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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Removing Group not working
Reply #3 - Aug 19th, 2010 at 7:20am
Print Post  
Does the error happen when hitting Del on the keyboard, or when processing ctxtMenuDelete.Click?
  
Back to top
 
IP Logged
 
srinivas
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 41
Joined: Jul 27th, 2010
Re: Removing Group not working
Reply #4 - Aug 19th, 2010 at 8:03am
Print Post  
Error is when running ctxtMenuDelete.Click event code, I am able to debug the code in ctxtMenuDelete.Click event.

Deletion is working fine for a diagram that I am designing but if I open a diagram that is previously saved and when I am trying to select the nodes and hit Delete, getting the error.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Removing Group not working
Reply #5 - Aug 19th, 2010 at 9:14am
Print Post  
Iterating diagram.Selection.Nodes and deleting each node might not work because this also modifies the Selection.Nodes collection. The framework does not allow removing collection elements while enumeration is in progress, so you must copy the Selection.Nodes elements to a new collection and then loop over the copy to delete nodes. Another possibility is to delete just the first node until the collection is empty:

Code
Select All
while (diagram.Selection.Nodes.Count > 0)
	diagram.Nodes.Remove(diagram.Selection.Nodes[0]); 



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


I love YaBB 1G - SP1!

Posts: 41
Joined: Jul 27th, 2010
Re: Removing Group not working
Reply #6 - Aug 19th, 2010 at 9:40am
Print Post  
Selected nodes are taken into another collection as below

DiagramItemCollection SelectedObjects = _fcMap.Selection.Items.Clone();

and then iterating thru selected objects as below
for (int i = 0; (i<= (SelectedObjects.Count - 1));i++)
{
MindFusion.Diagramming.DiagramItem CurOb = SelectedObjects[i];
DeleteChartObject(CurOb);
}

and in DeleteChartObject method removing the node using _fcMap.Items.Remove(CurOb);

When will NodeDeleted event has to be executed?

Implemented NodeDeleted method but not getting the control there, can I raise NodeDeleted event from code similar to NodeCreated?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Removing Group not working
Reply #7 - Aug 19th, 2010 at 9:52am
Print Post  
Deleting a node automatically deletes any DiagramLinks connected to it, so you will get that exception if SelectedObjects[i] is a link that has already been deleted.
  
Back to top
 
IP Logged
 
srinivas
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 41
Joined: Jul 27th, 2010
Re: Removing Group not working
Reply #8 - Aug 19th, 2010 at 1:22pm
Print Post  
Ok, got it working by removing other nodes except diagram item that has Group node first and then removed diagram items with Groups.

It was something difficult to locate the issue, NodeDeleted event was not required to be implemented.

Anyway it is working fine now, Thanks for your help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint