■ DiagramControl 클래스를 사용해 데이터 소스에서 다이어그램을 생성하는 방법을 보여준다.
▶ Item.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
namespace TestProject { /// <summary> /// 항목 /// </summary> public class Item { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 항목명 - Name /// <summary> /// 항목명 /// </summary> public string Name { get; set; } #endregion } } |
▶ Link.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
namespace TestProject { /// <summary> /// 링크 /// </summary> public class Link { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 시작 항목 - From /// <summary> /// 시작 항목 /// </summary> public object From { get; set; } #endregion #region 종료 항목 - To /// <summary> /// 종료 항목 /// </summary> public object To { get; set; } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
using System.Collections.Generic; using DevExpress.Diagram.Core; using DevExpress.XtraDiagram; using DevExpress.XtraEditors; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); #region 항목 리스트를 설정한다. List<Item> itemList = new List<Item>(); for(int i = 0; i < 5; i++) { itemList.Add(new Item { ID = i, Name = "Item " + i }); } #endregion #region 링크 리스트를 설정한다. List<Link> linkList = new List<Link>(); for(int i = 0; i < 4; i++) { linkList.Add(new Link { From = itemList[i].ID, To = itemList[i + 1].ID }); } linkList.Add(new Link { From = itemList[4].ID, To = itemList[0].ID }); #endregion #region 다이어그램 데이터 바인딩 컨트롤러를 설정한다. DiagramDataBindingController diagramDataBindingController = new DiagramDataBindingController(); diagramDataBindingController.DataSource = itemList; diagramDataBindingController.KeyMember = "ID"; diagramDataBindingController.ConnectorsSource = linkList; diagramDataBindingController.ConnectorFromMember = "From"; diagramDataBindingController.ConnectorToMember = "To"; diagramDataBindingController.LayoutKind = DiagramLayoutKind.Circular; #endregion diagramDataBindingController.GenerateItem += diagramDataBindingController_GenerateItem; diagramDataBindingController.Diagram = this.diagramControl; this.diagramControl.FitToDrawing(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 다이어그램 데이터 바인딩 컨트롤러 항목 생성시 처리하기 - diagramDataBindingController_GenerateItem(sender, e) /// <summary> /// 다이어그램 데이터 바인딩 컨트롤러 항목 생성시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void diagramDataBindingController_GenerateItem(object sender, DiagramGenerateItemEventArgs e) { DiagramShape item = new DiagramShape { X = 20, Width = 75, Height = 50, Shape = BasicShapes.Rectangle }; item.Bindings.Add(new DiagramBinding("Content", "Name")); e.Item = item; } #endregion } } |