Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Set Shape Text on NodeCreated (Read 3138 times)
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Set Shape Text on NodeCreated
Oct 24th, 2012 at 3:05am
Print Post  
How do I set the text of the shape when node is created?

So far its like this:

Code
Select All
 protected void diagramView_NodeCreated(object sender, NodeEventArgs e)
    {
        // setting constraint on aspect ratio
        e.Node.Constraints.KeepRatio = true;

        // setting height
        e.Node.Resize(40,40);

        //ShapeNode node = e.Node;

        // setting node id
        e.Node.Id  = "new"; 



How do I set its text displayed ?

In any case the ID does not seem to be set.

Because I did this in Page_Load:

Code
Select All
  // checking for any new node created and setting its Id to GUID and setting text
        foreach (ShapeNode node in diagramView.Diagram.Nodes)
        {
            if (node.Id == "new")
            {
                node.Id = System.Guid.NewGuid().ToString();
                node.Text = "Tag: ";
            }

        } 



...and it just doesnt seem to catch the node.id.

Infact when I do this...
Code
Select All
// checking for any new node created and setting its Id to GUID and setting text
        foreach (ShapeNode node in diagramView.Diagram.Nodes)
        {
            string nodeID = node.Id.ToString();

            node.Text = nodeID;


        } 



...it stops the shapes from being placed onto diagramView from shapeListBox altogether!
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Set Shape Text on NodeCreated
Reply #1 - Oct 24th, 2012 at 5:53am
Print Post  
This is how I temporarily solved it.

However I would appreciate a better solution, for some reason the iteration (foreach) seems quite inefficient to me:

Code
Select All
 protected void diagramView_NodeCreated(object sender, NodeEventArgs e)
    {
        // setting constraint on aspect ratio
        e.Node.Constraints.KeepRatio = true;

        // setting height
        e.Node.Resize(40,40);

        // setting shapenode text

        currNode = e.Node.ZIndex;


        foreach (ShapeNode node in diagramView.Diagram.Nodes)
        {
            if (node.ZIndex == currNode)
            {
                node.Text = "Current node: " + currNode;

            }
        }




    } 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Set Shape Text on NodeCreated
Reply #2 - Oct 24th, 2012 at 5:56am
Print Post  
Use the following pattern when you need to set node type -specific properties:

Code
Select All
ShapeNode shapeNode = e.Node as ShapeNode;
if (shapeNode != null)
{
    shapeNode.Text = "node 1";
    shapeNode.Shape = Shapes.Decision;
}

TableNode tableNode = e.Node as TableNode;
if (tableNode != null)
    ... 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Set Shape Text on NodeCreated
Reply #3 - Oct 24th, 2012 at 6:26am
Print Post  
Solved

Brilliant, thanks.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint