Using Windows Forms Control as a Node on a Diagram in MVC

This link takes reference:


I want to be able to add a CheckBox to my diagram that can save the checkbox state.

The above link reads: "InDepth\ControlsGalore sample that ships with the product."

I am using version 15.3.0.33 and cannot find any reference to this sample, perhaps it is outdated as the link is a post from 2005.

How can I use custom controls, such as CheckBox, on the diagram in my ASP.NET MVC application?

I also cannot find the Symbol Designer application that is referenced so I can create my own Symbols?

Thanks,

Neill

7 Replies 1 reply marked as answer

AR Aravind Ravi Syncfusion Team August 19, 2020 08:25 AM UTC

Hi Neil, 
 
By using the HTML node we can able to add check box to the Node. The shape property of node allows you to set the type of node and to create a HTML node it should be set as HTML. Please refer below code snippet for how to embed HTML node in the diagram 
 
List < DiagramNode > nodes = new List < DiagramNode > (); 
            nodes.Add(new DiagramNode() { 
                Id = "node1", 
                    Width = 100, 
                    Height = 100, 
                    OffsetX = 100, 
                    OffsetY = 100, 
                    Shape = new { type = "HTML", content= "<div style='height:100%;width:100%;'><input type='checkbox' value='checked'></div>" 
}, 
            }); 
            ViewBag.nodes = nodes; 
 
For more information about node shapes, please refer to below UG documentation link 
 
 
Regards 
Aravind Ravi 


Marked as answer

NE Neill August 19, 2020 10:29 AM UTC

Thank you Aravind,

I figured it out after reading through the documentation.

I see however that an HtmlNode cannot be exported to an image, which is a requirement so i'm not able to use that.

Thanks

Neill


AR Aravind Ravi Syncfusion Team August 20, 2020 06:25 AM UTC

Hi Neil, 
 
Currently, support to export the diagram into image format with the native and HTML nodes is not available. Since while exporting, the diagram will be drawn in a canvas, and then canvas is converted to image format. However, by using the Syncfusion Essential PDF library we can convert the HTML content to the image.  Syncfusion Essential PDF library is used, which supports HTML Content to Image conversion by using the advanced Qt WebKit rendering engine.  
 
We have already prepared a KB for How to print or export the HTML and Native node into image format using PDF. Similarly, you can refer this KB to export the HTML node into image format. 
 
 
Regards 
Aravind Ravi 



NE Neill August 20, 2020 06:45 AM UTC

Hi Aravind,

That's great, I will definitely look into it. 

For saving the diagram, in javascript, I save the diagram JSON string to the database using diagram.save().

If I use the HtmlNode to add a CheckBox to the diagram, how can I save the CheckBox checked / unchecked status to the diagram JSON string?

Thank,

Neill


AR Aravind Ravi Syncfusion Team August 21, 2020 04:41 AM UTC

Hi Neil, 
 
By default, in the diagram, if we use saveDiagram method to save the diagram means only diagram properties are get saved as string. After JSON object get returned from the saveDiagram method, parse the JSON string, so that you can get the individual objects in the diagram i.e. nodes, connectors. In that get the nodes and check if the checkbox is checked or not. If it is checked means , then change the content of the HTML node, if it does not checked means then do not change the content of the HTML node. After change the content again stringfy the JSON object and load the diagram. So that when you load the diagram, diagram is loaded with checkbox as checked. Please refer to the below code snippet 
 
var save; 
    document.getElementById('Save').onclick = function() { 
       save =  diagram.saveDiagram(); 
    } 
    document.getElementById('Load').onclick = function() { 
        var data = JSON.parse(save); 
        if (document.getElementById('check').checked) { 
        data["nodes"][0].shape.content = "<div style='height:100%;width:100%;'><input type='checkbox' value='checked' checked></div>"; 
        } 
        data = JSON.stringify(data); 
        diagram.loadDiagram(data); 
    } 
 
In the above code snippet, we have changed the content of the HTML node for the first node, similarly you can change the content of the other HTML node in JSON object, if check box is checked or not. 
 
Regards 
Aravind Ravi 



NE Neill August 21, 2020 07:59 AM UTC

Thank you for the information.

I can't seem to access the checkbox element directly?

Class code:

    HtmlNode HtmlNode = new HtmlNode();
    HtmlNode.TemplateId = "htmlTemplateCheckBox";
    model.Nodes.Add(HtmlNode);

View:

$('#btnSave').off().on('click', function () {
            var diagram = $("#Pictogram").ejDiagram("instance"); 
            var save = diagram.save();
            console.log(save.nodes[1]);      
        });




Apologies, had to add an image as the editor doesn't seem to allow script tags.



The console.log(save.nodes[1]) text:

  1. {fillColor: "white", borderColor: "black", borderWidth: 0, borderDashArray: "", opacity: 1, …}
    1. borderColor"black"
    2. borderDashArray""
    3. borderWidth0
    4. connectorPadding0
    5. constraints11026430
    6. contentAlignment"xmidymid"
    7. cornerRadius0
    8. cssClass""
    9. excludeFromLayoutfalse
    10. fillColor"white"
    11. gradientnull
    12. height50
    13. horizontalAlign"left"
    14. isExpandedtrue
    15. marginBottom0
    16. marginLeft0
    17. marginRight0
    18. marginTop0
    19. maxHeight0
    20. maxWidth0
    21. minHeight0
    22. minWidth0
    23. name"node_OFXr"
    24. offsetX200
    25. offsetY150
    26. opacity1
    27. parent""
    28. pathData""
    29. rotateAngle0
    30. scale"meet"
    31. shape""
    32. source""
    33. templateId"htmlTemplateCheckBox"
    34. textBlocknull
    35. type"html"
    36. verticalAlign"top"
    37. visibletrue
    38. width150
    39. zOrder1
    40. _cssClass""
    41. _scaledfalse
    42. _shape"html"
    43. _status"update"
    44. _type"node"


shape: "" ?
How do I access the checkbox element? 


Thanks,

Neill





AR Aravind Ravi Syncfusion Team August 24, 2020 11:39 AM UTC

Hi Neill, 

In EJ1 MVC we do not have support to change the HTML content at run time, because we set the template in nodeTemplate script in EJ1. So we do not able to access the HTML element used in node and cannot able to change it during save and load the diagram. 

Regards 
Aravind Ravi 


Loader.
Up arrow icon