We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Edit text in a textnode

Hi,

when I want to edit a text in a textnode I do the following steps:

1. look for the node.
2. Clone it. 
3. Delete the original one.
4. Assign the new text.
5. Append the new node into the diagram. 

This is the code that I use: 

            
            Node existeNode = f_parent.diagram1.Model.GetChildByName(nodeText.Name);

            if (existeNode != null)
            {
                TextNode tn = ((TextNode)nodeText).Clone() as TextNode;
                f_parent.diagram1.Model.RemoveChild(((TextNode)nodeText));
                tn.Text = "new text";
                f_parent.diagram1.Model.AppendChild(tn);
            }

Is there any way to make it more simple? Without clone and delete the original node? Doing that way I have problems when the zoom of the diagram is different of 100%

Thanks in advanced
            

        
    
           

11 Replies

SK Swarnesh Krishna Kumar Syncfusion Team July 13, 2015 07:00 AM UTC

Hi Blanca,
Thanks for using syncfusion products.

when I want to edit a text in a textnode I do the following steps:


1. look for the node.

2. Clone it. 

3. Delete the original one.

4. Assign the new text.

5. Append the new node into the diagram. 


This is the code that I use: 


            

            Node existeNode = f_parent.diagram1.Model.GetChildByName(nodeText.Name);


            if (existeNode != null)

            {

                TextNode tn = ((TextNode)nodeText).Clone() as TextNode;

                f_parent.diagram1.Model.RemoveChild(((TextNode)nodeText));

                tn.Text = "new text";

                f_parent.diagram1.Model.AppendChild(tn);

            }


Is there any way to make it more simple? Without clone and delete the original node?


Before looking into the requirement could you please provide us what is the actual intention for Cloning the original node and deleting the original node?


Since the requirement can be achieved by removing the existing node and adding the new node instead of cloning the original node.


If we misunderstand your requirement could you please provide us more information about your requirement which will help us to analyze further and provide you a better solution?

Doing that way I have problems when the zoom of the diagram is different of 100%


Could you please provide us more information probably a video and related files used in your application which reproduces the reported concern will help us to analyze further and provide you a better solution?


Please let us know if any concerns.
Regards,
Swarnesh K


BC Blanca Calderon July 13, 2015 07:15 AM UTC

Hi,

Then I don't need to clone the node? But the name of the new node will be different, won't be? I want to edit the text of the textnode but without losing the node name, is it possible? Could you send me an example?

And I send you a video with the problem with the zoom. 



Attachment: Video_1436778515_34b68200.zip


SK Swarnesh Krishna Kumar Syncfusion Team July 14, 2015 09:17 AM UTC

Hi Blanca,
Thanks for your update.

Then I don't need to clone the node? But the name of the new node will be different, won't be? I want to edit the text of the textnode but without losing the node name, is it possible? Could you send me an example?

We are glad to inform you that we have created a simple sample to achieve your requirement. We suggest you to remove the existing node and create a new node with respect to the existing node so that the old node is removed and new node has been created and same name has been assigned which is to be done in TextEditor_TextChanged event. Please refer the below code snippet and sample for your reference.


Here is the code snippet:


[C#]


diagram2.Controller.TextEditor.TextChanged+=TextEditor_TextChanged;


void TextEditor_TextChanged(object sender, EventArgs e)

{

//Removing the Existing node.

this.diagram2.Model.RemoveChild(((TextNode)existeNode));

//Creation of new node.

TextNode Tn2 = ((TextNode)existeNode) as TextNode;

//Assigning the existing node’s name to the new node.

Tn2.Name = existeNode.Name;

}


Here is the Sample:


Sample



And I send you a video with the problem with the zoom. 






We suggest you to update the TextNode’s font size based on the size of the node. Please refer the below code snippet and video for your reference.


Here is the code snippet:


Tn2.Text = "This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node This is the Text Node";

Tn2.SizeToText(new SizeF(Tn2.Text.Length, Tn2.Size.Height));

Tn2.WrapText = true;


Here is the Video:


Video


Please let us know if any concerns.
Regards,
Swarnesh K


BC Blanca Calderon July 15, 2015 09:50 AM UTC

Sorry but it doesn't work. 

If I don't use clone the textnode text doesn't change. And If I use clone option,  works but the zoom doesn't work. 

In the video that I send you doesn't appear:

Tn2.SizeToText(new SizeF(Tn2.Text.Length, Tn2.Size.Height));

n2.WrapText = true;


I have tried it but the result it's the same.


Attachment: Video_1436960644_5f686131.zip


NG Naganathan Ganesh Babu Syncfusion Team July 16, 2015 12:46 PM UTC

Hi Blanca,
 
Thanks for your update.
 
We have created a simple sample to achieve your requirement. We suggest you to use TextEditor’s “EndEdit” method and pass the parameter as false in order to achieve your requirement. Please refer the below code snippet and sample for your references.
 
Here is the code snippet:
[C#]
diagram1.Controller.TextEditor.EndEdit(false);
 
Here is the video:
Video
 
Here is the sample:
Sample
 
Please let us know if any concerns.
 
Regards,
 
Naganathan K G


BC Blanca Calderon July 17, 2015 05:47 AM UTC

Ok,

diagram1.Controller.TextEditor.EndEdit(false); works fine but the problem with the zoom it is different.

If the magnification is different from 100%, the fontsize of the node changes (eg. zoom 250%, fontsize=30.0), always bigger that the original size, 12.
 I don't know why the Font size of the textnode changes but it happens.

Using this code avoid the problem:

if (tn.FontStyle.Size != 12)

{

tn.FontStyle.Size = 12;

}

But I think the fontsize should remain the same.


 
 


SK Swarnesh Krishna Kumar Syncfusion Team July 20, 2015 12:53 PM UTC

Hi Blanca,
Thanks for your patience.
We are able to reproduce the issue reported by you at our end. We have forwarded this to our development team for further analysis. We will update you with our development team’s response in one business day 21st July 2015.
Please let us know if any concerns.
Regards,
Swarnesh K


BC Blanca Calderon July 21, 2015 06:55 AM UTC

Ok, thank you so much.


SK Swarnesh Krishna Kumar Syncfusion Team July 21, 2015 08:58 AM UTC

Hi Blanca,
Thanks for your update.
We are glad to inform you that we have successfully achieved your requirement by modifying the sample. We suggest you to pass “true” in diagram1.Controller.TextEditor.EndEdit’s parameter to avoid changing of font size. We have attached the modified sample, code snippet and video for your reference.
Here is the code snippet:
[C#]
diagram1.Controller.TextEditor.EndEdit(true);
Here is the modified Sample:
Sample
Here is the Video:
Video
Please let us know if any concerns.
Regards,
Swarnesh K



BC Blanca Calderon replied to Swarnesh Krishna Kumar July 21, 2015 09:05 AM UTC

Hi Blanca,
Thanks for your update.
We are glad to inform you that we have successfully achieved your requirement by modifying the sample. We suggest you to pass “true” in diagram1.Controller.TextEditor.EndEdit’s parameter to avoid changing of font size. We have attached the modified sample, code snippet and video for your reference.
Here is the code snippet:
[C#]
diagram1.Controller.TextEditor.EndEdit(true);
Here is the modified Sample:
Sample
Here is the Video:
Video
Please let us know if any concerns.
Regards,
Swarnesh K


Yes, this time yes, thank you!


NG Naganathan Ganesh Babu Syncfusion Team July 23, 2015 04:36 AM UTC

Hi Blanca,
Thanks for your update.
We are happy to assist you and please let us know if you need any further assistance.
Regards,
Naganathan K G

Loader.
Live Chat Icon For mobile
Up arrow icon