Diagram Objects in a List or array

2 posts, 0 answers
  1. Jacques
    Jacques avatar
    4 posts
    Member since:
    Jan 2019

    Posted 28 Jan Link to this post

    Hi.

    Is there a way to get the text box values from the from the objects in my diagram into an array or a list? I would like to use the text box string values of the objects on the diagram values for program logic. 

    Then i would also like t get all the X and Y coordinates of each object on the diagram into a list that will enable me to write logic based on the position of the X and Y values of my objects in my diagram.

    Thank You!
    Jacques

  2. Hristo
    Admin
    Hristo avatar
    1508 posts

    Posted 29 Jan Link to this post

    Hi Jacques,

    You can iterate the Shapes collection of the diagram store whatever information is necessary. It is also possible to use the SaveLoad API and retrieve the XML representation of the entire control. This will include information about the shapes names, position, connections etc. Calling the Save method on the diagram will also fire the ShapeSerialized event for each of the shapes. You can handle it add access the entity object and its properties. The event also exposes a SerializationInfo object giving information about the serialized data per shape: 
    private void RadDiagram1_ShapeSerialized(object sender, Telerik.Windows.Diagrams.Core.SerializationEventArgs<Telerik.Windows.Diagrams.Core.IShape> e)
    {
        RadDiagramShape shape = e.Entity as RadDiagramShape;
        if (shape != null)
        {
            string text = shape.Text;
            Telerik.Windows.Diagrams.Core.Point position = shape.Position;
     
            string serializedText = e.SerializationInfo[SerializationConstants.ShapeText]?.ToString();
            string serializedPostion = e.SerializationInfo[SerializationConstants.Position]?.ToString();
        }           
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        string xmlData = this.radDiagram1.Save();
    }

    I hope this will help. Let me know if you have other questions.

    Regards,
    Hristo
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top