| |
 |
Generating Diagrams from a Data Source
The DiagramDataBindingController class provides the data binding functionality for the DiagramControl. To bind the DiagramControl to data, open its Smart Tag panel and select Add DataBindingController.

To configure the data source, go to the diagramDataBindingController's Smart Tag.

The following table lists the properties used to map a diagram to data.
Tip
The Item Template Designer allows you to design templates for diagram items and connectors at design time.
The following example demonstrates the DiagramControl bound to sample data.

C# |
public class ViewModel {
public List<Item> Items { get; set; }
public List<Link> Connections { get; set; }
public ViewModel() {
Items = new List<Item>();
for (int i = 0; i < 5; i++)
Items.Add(new Item { Id = i, Name = "Item " + i });
Connections = new List<Link>();
for (int i = 0; i < 4; i++)
Connections.Add(new Link { From = Items[i].Id, To = Items[i + 1].Id });
Connections.Add(new Link { From = Items[4].Id, To = Items[0].Id });
}
}
public class Item {
public int Id { get; set; }
public string Name { get; set; }
}
public class Link {
public object From { get; set; }
public object To { get; set; }
}
|
C# |
public Form1() {
InitializeComponent();
ViewModel viewModel = new ViewModel();
diagramDataBindingController1.GenerateItem += DiagramDataBindingController1_GenerateItem;
diagramDataBindingController1.DataSource = viewModel.Items;
diagramDataBindingController1.KeyMember = "Id";
diagramDataBindingController1.ConnectorsSource = viewModel.Connections;
diagramDataBindingController1.ConnectorFromMember = "From";
diagramDataBindingController1.ConnectorToMember = "To";
diagramDataBindingController1.LayoutKind = DiagramLayoutKind.Circular;
}
private void DiagramDataBindingController1_GenerateItem(object sender, DiagramGenerateItemEventArgs e) {
var item = new DiagramShape {
X = 27,
Width = 75,
Height = 50,
Shape = BasicShapes.Rectangle
};
item.Bindings.Add(new DiagramBinding("Content", "Name"));
e.Item = item;
}
|
Is this topic helpful?
Additional Feedback
Close
|