# diagram-dynamic-properties

> Diagram where selected shape properties are bound to a PropertyGrid that updates the underlying node on every change in the palette.

**Framework:** winforms  **Component:** Diagram  **Variant:** dynamic-properties

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/winforms/diagram-dynamic-properties.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Diagram.Windows
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/diagram-dynamic-properties/diagram.Designer.cs

```cs
namespace DynamicProperties
{
    public partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            diagram1 = new Syncfusion.Windows.Forms.Diagram.Controls.Diagram(components);
            model1 = new Syncfusion.Windows.Forms.Diagram.Model(components);
            button1 = new System.Windows.Forms.Button();
            panel3 = new System.Windows.Forms.Panel();
            label1 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)diagram1).BeginInit();
            ((System.ComponentModel.ISupportInitialize)model1).BeginInit();
            panel3.SuspendLayout();
            SuspendLayout();
            // 
            // diagram1
            // 
            diagram1.Controller.Constraint = Syncfusion.Windows.Forms.Diagram.Constraints.PageEditable;
            diagram1.Controller.DefaultConnectorTool = Syncfusion.Windows.Forms.Diagram.ConnectorTool.OrgLineConnectorTool;
            diagram1.Controller.Nodes = null;
            diagram1.Controller.PasteOffset = new System.Drawing.SizeF(10F, 10F);
            diagram1.Dock = System.Windows.Forms.DockStyle.Fill;
            diagram1.EnableTouchMode = false;
            diagram1.HScroll = true;
            diagram1.Location = new System.Drawing.Point(0, 0);
            diagram1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            diagram1.Model = model1;
            diagram1.Name = "diagram1";
            diagram1.Size = new System.Drawing.Size(784, 788);
            diagram1.SmartSizeBox = false;
            diagram1.TabIndex = 1;
            diagram1.Text = "diagram1";
            diagram1.TouchMode = false;
            // 
            // 
            // 
            diagram1.View.Grid.MinPixelSpacing = 4F;
            diagram1.View.Magnification = 100F;
            diagram1.View.ZoomType = Syncfusion.Windows.Forms.Diagram.ZoomType.Center;
            diagram1.VisualStyle = Syncfusion.Windows.Forms.Diagram.Controls.DiagramStyle.Default;
            diagram1.VScroll = true;
            // 
            // model1
            // 
            model1.BackgroundStyle.PathBrushStyle = Syncfusion.Windows.Forms.Diagram.PathGradientBrushStyle.RectangleCenter;
            model1.CustomUnitValue = 0.5F;
            model1.DocumentScale.DisplayName = "No Scale";
            model1.DocumentScale.Height = 1F;
            model1.DocumentScale.Width = 1F;
            model1.DocumentSize.Height = 1169F;
            model1.DocumentSize.Width = 827F;
            model1.LineStyle.DashPattern = null;
            model1.LineStyle.LineColor = System.Drawing.Color.Black;
            model1.LogicalSize = new System.Drawing.SizeF(827F, 1169F);
            model1.ShadowStyle.Color = System.Drawing.Color.FromArgb(128, 105, 105, 105);
            model1.ShadowStyle.ForeColor = System.Drawing.Color.FromArgb(128, 105, 105, 105);
            // 
            // button1
            // 
            button1.FlatAppearance.BorderColor = System.Drawing.Color.Silver;
            button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            button1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
            button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            button1.Location = new System.Drawing.Point(657, 25);
            button1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            button1.Name = "button1";
            button1.Size = new System.Drawing.Size(148, 45);
            button1.TabIndex = 0;
            button1.Text = "Edit Info";
            button1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

            button1.UseVisualStyleBackColor = true;
            button1.Click += button1_Click;
            // 
            // panel3
            // 
            panel3.Controls.Add(diagram1);
            panel3.Dock = System.Windows.Forms.DockStyle.Bottom;
            panel3.Location = new System.Drawing.Point(0, 75);
            panel3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            panel3.Name = "panel3";
            panel3.Size = new System.Drawing.Size(784, 788);
            panel3.TabIndex = 0;
            // 
            // label1
            // 
            label1.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
            label1.Location = new System.Drawing.Point(-1, 25);
            label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
            label1.Name = "label1";
            label1.Size = new System.Drawing.Size(641, 49);
            label1.TabIndex = 1;
            label1.Text = "Move the mouse pointer over the node to view the additional data associated with the node. Also,  you can edit the data by selecting the node, and clicking the EditInfo button";
            // 
            // Form1
            // 
            AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
            AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            ClientSize = new System.Drawing.Size(784, 863);
            Controls.Add(label1);
            Controls.Add(panel3);
            Controls.Add(button1);
            Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            MaximizeBox = false;
            Name = "Form1";
            StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            Text = "DynamicProperties";
            Load += Form1_Load;
            ((System.ComponentModel.ISupportInitialize)diagram1).EndInit();
            ((System.ComponentModel.ISupportInitialize)model1).EndInit();
            panel3.ResumeLayout(false);
            ResumeLayout(false);

        }

        #endregion

        private Syncfusion.Windows.Forms.Diagram.Controls.Diagram diagram1;
        private Syncfusion.Windows.Forms.Diagram.Model model1;
        private System.Windows.Forms.Panel panel3;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
    }
}

```

### src/components/diagram-dynamic-properties/diagram.cs

```cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Syncfusion.Windows.Forms.Diagram;
using System.Xml;
using System.Drawing.Drawing2D;
using System.Collections;
using Syncfusion.Windows.Forms;

namespace DynamicProperties
{
    public partial class Form1 : MetroForm
    {
        #region Members
        protected RadialTreeLayoutManager dtLayoutMgr;
        ToolTip tooltips = new ToolTip();
        #endregion

        #region initializeForm
        public Form1()
        {
            InitializeComponent();
        }
        #endregion

        #region Events
        private void Form1_Load(object sender, EventArgs e)
        {
            diagram1.Model.BeginUpdate();
            this.diagram1.Controller.InPlaceEditing = false;
            this.dtLayoutMgr = new RadialTreeLayoutManager(this.diagram1.Model, 0, 80, 80);
            dtLayoutMgr.LeftMargin = 80;
            dtLayoutMgr.TopMargin = 30;
            dtLayoutMgr.AutoLayout = true;
            diagram1.LayoutManager = dtLayoutMgr;
            DiagramAppearance();
#if !NETCORE
            InitializeDiagramFromXMLData(@"..\..\..\..\..\..\common\Data\Diagram\xml\DynamicProperties.xml");
#else
            string dynamicXml = DynamicPropertiesDataSource.GetXmlPath();
            if (dynamicXml != null)
            {
                InitializeDiagramFromXMLData(dynamicXml);
            }
#endif
            diagram1.Model.EndUpdate();
            diagram1.View.SelectionList.Clear();
            CenterDiagram();
            diagram1.Resize += (s, args) => CenterDiagram();
            diagram1.EventSink.NodeMouseEnter += new NodeMouseEventHandler(EventSink_NodeMouseEnter);
            diagram1.EventSink.NodeMouseLeave += new NodeMouseEventHandler(EventSink_NodeMouseLeave);
        }

        /// <summary>Re-applies the radial layout so that the diagram is horizontally centered.</summary>
        private void CenterDiagram()
        {
            if (dtLayoutMgr == null || diagram1.ClientSize.Width <= 0 || diagram1.Model.Nodes.Count == 0)
            {
                return;
            }

            float left = float.MaxValue, right = float.MinValue;
            foreach (Syncfusion.Windows.Forms.Diagram.Node node in diagram1.Model.Nodes)
            {
                left = Math.Min(left, node.BoundingRectangle.Left);
                right = Math.Max(right, node.BoundingRectangle.Right);
            }

            float contentWidth = right - left;
            float margin = Math.Max(0, (diagram1.ClientSize.Width - contentWidth) / 2);
            float shift = margin - (left - dtLayoutMgr.LeftMargin);
            if (Math.Abs(shift - dtLayoutMgr.LeftMargin) < 1)
            {
                return;
            }

            dtLayoutMgr.LeftMargin = shift;
            dtLayoutMgr.UpdateLayout(null);
        }

        void EventSink_NodeMouseLeave(NodeMouseEventArgs evtArgs)
        {
            tooltips.Active = false;
        }

        void EventSink_NodeMouseEnter(NodeMouseEventArgs evtArgs)
        {
            if (!(evtArgs.Node is ConnectorBase) && evtArgs.Node.PropertyBag.Count > 0)
            {
                tooltips.IsBalloon = true;
                string strData = string.Empty;
                foreach (string key in evtArgs.Node.PropertyBag.Keys)
                {
                    strData += key + " : " + evtArgs.Node.PropertyBag[key] + "\n";
                }
                tooltips.SetToolTip(this.diagram1, strData);
                tooltips.Active = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (diagram1.View.SelectionList.Count > 0)
            {
                PropertyBagDialog propertyBagDialog = new PropertyBagDialog();
                propertyBagDialog.PropertyBag = diagram1.View.SelectionList[0].PropertyBag;
                propertyBagDialog.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please select a node to edit property info collection  ", "Meesage");
            }
        }
#endregion

#region Private Methods
        /// <summary>
        /// Change's the appearance of Diagram
        /// </summary>
        private void DiagramAppearance()
        {            
            this.diagram1.Model.LineStyle.LineColor = Color.Transparent;
            this.diagram1.View.HandleRenderer.HandleColor = Color.AliceBlue;
            this.diagram1.View.HandleRenderer.HandleOutlineColor = Color.SkyBlue;
            this.diagram1.Model.RenderingStyle.SmoothingMode = SmoothingMode.HighQuality;
            this.diagram1.Model.BoundaryConstraintsEnabled = false;
            this.diagram1.View.BackgroundColor = Color.White;
            this.diagram1.View.Grid.Visible = false;
            this.diagram1.View.SelectionList.Clear();
        }
#endregion

#region Initailize Diagram
        
        /// <summary>
        /// Initialize diagram from XML file
        /// </summary>
        /// <param name="datasrcpath">Path of the XML file</param>
        protected void InitializeDiagramFromXMLData(string datasrcpath)
        {
            Hashtable lstEmployees = this.ReadEmployeeDataFromXMLFile(datasrcpath);

            // Create a manager-employee nested list with top-level employees forming the root nodes
            ArrayList sortedlist = this.GetSortedEmployeesList(lstEmployees);

            foreach (Employee emply in sortedlist)
            {
                this.IterUpdateSubEmployeeCount(emply);
            }

            // Create diagram symbol nodes for each employee and initialize the diagram
            this.CreateOrgDiagramFromList(sortedlist);
            lstEmployees.Clear();
            sortedlist.Clear();
        }

        /// <summary>
        /// New function for reading data from xml file
        /// </summary>
        /// <param name="datasrc">XML File</param>
        protected Hashtable ReadEmployeeDataFromXMLFile(string datasrc)
        {
            Hashtable lstEmployee = new Hashtable();  

            // Use the XML DOM to read data from the employees XML data file
            XmlDocument xmldoc = new XmlDocument();
#if SyncfusionFramework4_0
            xmldoc.XmlResolver = null;
#endif
            xmldoc.Load(datasrc);
            if (xmldoc.DocumentElement.HasChildNodes)
            {
                XmlNodeList employeelist = xmldoc.DocumentElement.ChildNodes;
                for (int i = 0; i < employeelist.Count; i++)
                {
                    // Create an Employee instance to represent each employee
                    Employee emply = new Employee();

                    XmlNode employeenode = employeelist[i];
                    XmlNodeList employeedatalist = employeenode.ChildNodes;
                    IEnumerator employeedata = employeedatalist.GetEnumerator();
                    employeedata.Reset();
                    while (employeedata.MoveNext())
                    {
                        XmlNode dataelement = employeedata.Current as XmlNode;
                        switch (dataelement.Name)
                        {
                            case "Name":
                                emply.EmployeeName = dataelement.InnerText;
                                break;
                            case "EmployeeID":
                                emply.EmployeeID = dataelement.InnerText;                                
                                break;
                            case "Designation":
                                emply.Designation = dataelement.InnerText;                                
                                break;
                            case "DOJ":
                                emply.DOJ = dataelement.InnerText;                                
                                break;
                            case "ImageNo":
                                emply.ImageName = dataelement.InnerText;
                                break;
                            case "ManagerID":
                                emply.ManagerID = dataelement.InnerText;
                                break;
                        }
                    }
                    lstEmployee.Add(emply.EmployeeID,emply);
                }
            }
            return lstEmployee;
        }

        /// <summary>
        ///  Rearrange the employees collection as a manager-subemployee nested tree
        /// </summary>
        /// <param name="htemployees">Employee table</param>
        /// <returns>returns the sorted list</returns>
        protected ArrayList GetSortedEmployeesList(Hashtable htemployees)
        {
            ICollection employees = htemployees.Values;
            ArrayList sortedlist = new ArrayList();
            foreach (Employee emply in employees)
            {
                if (emply.ManagerID == string.Empty)
                {
                    // Employees without a ManagerID are top-level nodes in the org tree
                    sortedlist.Add(emply);
                }
                else
                {
                    // Find the employee instance associated with the managerID and add this object as 
                    // a subemployee of the manager node.
                    Employee manager = (Employee)htemployees[emply.ManagerID];
                    if (manager != null)
                        manager.SubEmployees.Add(emply);
                }
            }

            return sortedlist;
        }

        /// <summary>
        /// generates the sub employees count
        /// </summary>
        /// <param name="empl">Employee business object</param>
        protected void IterUpdateSubEmployeeCount(Employee empl)
        {
            empl.RecSubEmployeeCount = empl.SubEmployees.Count;
            foreach (Employee subempl in empl.SubEmployees)
            {
                this.IterUpdateSubEmployeeCount(subempl);
                empl.RecSubEmployeeCount += subempl.RecSubEmployeeCount;
            }
        }

        /// <summary>
        /// Create diagram symbol nodes for each employee in the organization and add these symbols to the diagram
        /// Create links between manager and sub-employees to depict the org structure
        /// </summary>
        /// <param name="alemployees"> Employees list</param>
        protected void CreateOrgDiagramFromList(ArrayList alemployees)
        {
            // Temporarily suspend the Diagram Model redrawing
            this.diagram1.Model.BeginUpdate();

            foreach (Employee emply in alemployees)
            {
                string fileName = DynamicPropertiesDataSource.GetEmployeeImagePath(emply.ImageName);
                BitmapNode employeeSymbol = new BitmapNode(new Bitmap(fileName), new RectangleF(100,100,75,75));
                employeeSymbol.LineStyle.LineColor = Color.Transparent;
                employeeSymbol.PropertyBag.Add("Name",emply.EmployeeName);
                employeeSymbol.PropertyBag.Add("ID", emply.EmployeeID);
                employeeSymbol.PropertyBag.Add("Designation", emply.Designation);
                this.diagram1.Model.AppendChild(employeeSymbol);
                this.IterCreateEmployeeSymbol(emply, employeeSymbol);
            }

            // Enable the Model redraw
            this.diagram1.Model.EndUpdate();

            // Instruct the LayoutManager to calculate and layout the diagram nodes
            LayoutNodes();
        }

        /// <summary>
        ///  Iterative sub-employee symbol node creation
        /// </summary>
        /// <param name="emply">Employess business object</param>
        /// <param name="emplysymbol">Employee Node</param>
        protected void IterCreateEmployeeSymbol(Employee emply, BitmapNode bmpNode)
        {
            foreach (Employee subemply in emply.SubEmployees)
            {
                string fileName = DynamicPropertiesDataSource.GetEmployeeImagePath(subemply.ImageName);
                // Create a BitmapNode for each of the sub-employees of the particular employee 
                BitmapNode subemplysymbol = new BitmapNode(new Bitmap(fileName), new RectangleF(100, 100, 75, 75));
                subemplysymbol.LineStyle.LineColor = Color.Transparent;
                subemplysymbol.PropertyBag.Add("Name", subemply.EmployeeName);
                subemplysymbol.PropertyBag.Add("ID", subemply.EmployeeID);
                subemplysymbol.PropertyBag.Add("Designation", subemply.Designation);
                this.diagram1.Model.AppendChild(subemplysymbol);

                bmpNode.EnableCentralPort = true;
                subemplysymbol.EnableCentralPort = true;
                ConnectNodes(bmpNode, subemplysymbol);

                this.IterCreateEmployeeSymbol(subemply, subemplysymbol);
            }

        }

        /// <summary>
        /// Connects the nodes
        /// </summary>
        /// <param name="parent">Parent Node</param>
        /// <param name="child">Child node</param>
        private void ConnectNodes(Node parent, Node child)
        {
            LineConnector lConnector = new LineConnector(PointF.Empty, new PointF(0, 1));
            lConnector.LineStyle.LineWidth = 1f;
            lConnector.LineStyle.LineColor = Color.Black;
            lConnector.HeadDecorator.DecoratorShape = DecoratorShape.Filled45Arrow;            
            lConnector.HeadDecorator.FillStyle.Color = Color.White;
            this.diagram1.Model.AppendChild(lConnector);

            if (parent.CentralPort != null && child.CentralPort != null)
            {
                parent.CentralPort.TryConnect(lConnector.TailEndPoint);
                child.CentralPort.TryConnect(lConnector.HeadEndPoint);
            }

            this.diagram1.Controller.SendToBack();
        }
    
#endregion
        
#region Helper Methods

        private void LayoutNodes()
        {
            // Temporarily suspend the layoutmanager
            this.diagram1.LayoutManager.AutoLayout = false;

            this.diagram1.LayoutManager.Nodes.Clear();
            this.diagram1.LayoutManager.Nodes.AddRange(this.diagram1.Model.Nodes);
            this.diagram1.LayoutManager.UpdateLayout(null);
        }
#endregion
    }
}

```
