첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ Item.cs

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
    }
}

 

728x90

 

▶ Link.cs

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
    }
}

 

300x250

 

▶ MainForm.cs

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요