Ticket T332969
Visible to All Users

How to generate shapes in DiagramControl from a hierarchical source

created 9 years ago

Dear support,

I have a data table, coming from an SQL database, which I want to display it as a diagram. Currently, I'm loading these data into a tree list control and I make them visible on a hierarchical format with roots and children nodes. I saw that this new control supports as input only XML files.

Based on this, can you please provide me a guideline how to convert those data into an XML file that the diagram control will understand? Do I need to follow an XML schema? Please advice the best solution in order to implement this requirement.

Best regards,
Andreas

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hi Andreas,
Although it's possible to manually create an XML file in a format supported by DiagramControl, I think it would be easier to iterate through items in your source and create required items in code. You can learn how to create diagrams in code in our demo: Demo Center -> Win -> Diagrams -> Main Demo -> Code First. What do you think about this approach?
We are going to support generation of diagrams from sources out of the box in future versions.

[Updated]
Another solution is to use the OrgChartController class. It is already used in WPF in the DiagramOrgChartBehavior class, however currently there are no such wrappers in WinForms. As a solution, I suggest that you create a class that implements the IOrgChartBehavior interface and then use it in OrgChartController. I have attached a sample project to demonstrate this approach.

Thanks,
Alexander

    Show previous comments (5)
    Alexander Russkov (DevExpress) 9 years ago

      Hi Andreas,
      I suggest that you set required properties in the function accepted by the OrgChartBehavior constructor:

      C#
      OrgChartBehavior<Customer>(c => new DiagramShape(BasicShapes.Rectangle, 50, 10, 200, 100, c.Name))

      As for connectors, at the moment, there is no easy way to modify them depending on data. However, we are going to improve this functionality in the near future.
      Currently, you can customize them only independently of data objects. To accomplish this task, crate a DiagramControl descendant and implement the IDiagramControl.CreateConnector method. I have attached a sample project.

      Thanks,
      Alexander

      AO AO
      Andreas.Oikonomidis 9 years ago

        Alexander,
        Before proceeding to the connectors solution you just provided, I tried to implement the OrgChartController class approach. I made all the needed adjustments to cover the name, key and parent values but now I'm getting the attached runtime error on the stage the controller is getting my data source ("OnItemsSourceChanged" method).
        Any ideas why this is happening? All 3 (name, key and parent) fields have values for all the items in the list I'm sending to the class.
        Regards,
        Andreas

        Alexander Russkov (DevExpress) 9 years ago

          Hi Andreas,
          To process your recent post more efficiently, I created a separate ticket on your behalf: T336371: NullReferenceException is raised when the OrgChartController.OnItemsSourceChanged method is called.

          Thanks,
          Alexander

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.