Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Problem about Node and Group (Read 2257 times)
airmix
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Nov 12th, 2006
Problem about Node and Group
Dec 1st, 2006 at 2:33am
Print Post  
There is a group structure, A group has B .......

node struct is
{A -> B -> C -> D}
first delete C , then delete B and add E after D. Next delete D and add F after E. Finally delete E

At this moment, Null Reference Exception happen!!!
I dont understand why error will occur, plz help!!

Box de = userChart.Selection.Boxes[0];
Group parent = box.MasterGroup;
Group sub = box.SubordinateGroup;
Box main = ((Box)parent.MainObject);
Group master = userChart.FindGroup(main.Tag);
for(int i = 0; i < sub.AttachedObjects.Count; i++)
{
     Box b = (Box)sub.AttachedObjects[i];   
     master.AttachedObjects.Add(b);
     master.AttachToCorner(b,0);
     Arrow link = userChart.CreateArrow(main, b);
}
userChart.DeleteObject(de);
rearrange(); <----- Refresh treelayout

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem about Node and Group
Reply #1 - Dec 1st, 2006 at 5:32am
Print Post  
Calling

master.AttachToCorner(b,0);

will automatically add b to "master.AttachedObjects". Try that without the

master.AttachedObjects.Add(b);

line. Otherwise you will end up with two references to "b" in the collection and that might lead to problems.

Stoyan
  
Back to top
 
IP Logged
 
airmix
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Nov 12th, 2006
Re: Problem about Node and Group
Reply #2 - Dec 1st, 2006 at 5:57am
Print Post  
Thanks for your fast reply!!! Grin
But also not work
at last Node E does not contain any Master Group
(origial design is A will contain E, then i could delete E too, but i want to delete E, Null Reference in the MasterGroup and its MainOject)
Help!!!! Stoyo
THX
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem about Node and Group
Reply #3 - Dec 1st, 2006 at 6:34am
Print Post  
What does "add E after D" mean? Could you email me your initial diagram from which I should start deleting and adding stuff?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem about Node and Group
Reply #4 - Dec 1st, 2006 at 8:20am
Print Post  
Hi,

It seems the "Group master" variable did not point correctly to the parent group. This code seems to work better:

Code
Select All
if(userChart.Selection.Boxes.Count > 0)
{
  Box de = userChart.Selection.Boxes[0];
  Group parent = de.MasterGroup;
  Group sub = de.SubordinateGroup;
  Box main = ((Box)parent.MainObject);

  for(int k = 0; k < sub.AttachedObjects.Count; k++)
  {
    Box b = (Box)sub.AttachedObjects[k];
    b.AttachTo(main, AttachToNode.TopLeft);
    Arrow link = userChart.CreateArrow(main, b);
  }
  userChart.DeleteObject(de);
  rearrange();
}
 



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