Hi,
We’ve tried the tree data importer with the same sample data you have specified in your post:
DataTable table = new DataTable();
table.Columns.Add("Id", typeof(int));
table.Columns.Add("ParentId", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(1, null, "BOSS");
table.Rows.Add(2, 1, "JOHN");
table.Rows.Add(3, 2, "MIKE");
table.Rows.Add(4, 2, "SUE");
All you have to do next is to create a simple tree data importer:
// create the tree data source importer
m_TreeImporter = new NTreeDataSourceImporter();
// set the document in the active layer of which the shapes will be imported
m_TreeImporter.Document = document;
// set the data source
m_TreeImporter.DataSource = table;
// records are uniquely identified by their Id column
// records link to their parent record by their ParentId column
m_TreeImporter.IdColumnName = "Id";
m_TreeImporter.ParentIdColumnName = "ParentId";
// create vertices as rectangles shapes, with default size (60,30)
NBasicShapesFactory shapesFactory = new NBasicShapesFactory();
shapesFactory.DefaultSize = new NSizeF(60, 30);
m_TreeImporter.VertexShapesFactory = shapesFactory;
m_TreeImporter.VertexShapesName = BasicShapes.Rectangle.ToString();
// set stylesheets to be applied to imported vertices and edges
m_TreeImporter.VertexStyleSheetName = "Vertices";
m_TreeImporter.EdgeStyleSheetName = "Edges";
// use layered tree layout
NLayeredTreeLayout layout = new NLayeredTreeLayout();
layout.Direction = LayoutDirection.LeftToRight;
layout.OrthogonalEdgeRouting = true;
layout.LayerAlignment = RelativeAlignment.Near;
m_TreeImporter.Layout = layout;
// subscribe for the vertex imported event,
// which is raised when a shape was created for a data source record
m_TreeImporter.VertexImported += new ShapeImportedDelegate(OnVertexImported);
// import
m_TreeImporter.Import();
The result of the import will be the attached diagram.
Best Regards,
Nevron Support Team