첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

using System;

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox repositoryItemComboBox;

        /// <summary>
        /// 서유럽 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox westernEuropeRepositoryItemComboBox;

        /// <summary>
        /// 동유럽 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox easternEuropeRepositoryItemComboBox;

        /// <summary>
        /// 북미 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox northAmericaRepositoryItemComboBox;

        /// <summary>
        /// 남미 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox southAmericaRepositoryItemComboBox;

        /// <summary>
        /// 아시아 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox asiaRepositoryItemComboBox;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            this.repositoryItemComboBox = new RepositoryItemComboBox();

            this.repositoryItemComboBox.Items.Add("Western Europe");
            this.repositoryItemComboBox.Items.Add("Eastern Europe");
            this.repositoryItemComboBox.Items.Add("North America" );
            this.repositoryItemComboBox.Items.Add("South America" );
            this.repositoryItemComboBox.Items.Add("Asia"          );

            this.westernEuropeRepositoryItemComboBox = new RepositoryItemComboBox();

            this.westernEuropeRepositoryItemComboBox.Items.Add("Austria"       );
            this.westernEuropeRepositoryItemComboBox.Items.Add("France"        );
            this.westernEuropeRepositoryItemComboBox.Items.Add("Germany"       );
            this.westernEuropeRepositoryItemComboBox.Items.Add("Spain"         );
            this.westernEuropeRepositoryItemComboBox.Items.Add("Switzerland"   );
            this.westernEuropeRepositoryItemComboBox.Items.Add("United Kingdom");

            this.easternEuropeRepositoryItemComboBox = new RepositoryItemComboBox();

            this.easternEuropeRepositoryItemComboBox.Items.Add("Belarus" );
            this.easternEuropeRepositoryItemComboBox.Items.Add("Bulgaria");
            this.easternEuropeRepositoryItemComboBox.Items.Add("Croatia" );
            this.easternEuropeRepositoryItemComboBox.Items.Add("Russia"  );

            this.northAmericaRepositoryItemComboBox = new RepositoryItemComboBox();

            this.northAmericaRepositoryItemComboBox.Items.Add("USA"   );
            this.northAmericaRepositoryItemComboBox.Items.Add("Canada");

            this.southAmericaRepositoryItemComboBox = new RepositoryItemComboBox();

            this.southAmericaRepositoryItemComboBox.Items.Add("Argentina");
            this.southAmericaRepositoryItemComboBox.Items.Add("Brazil"   );

            this.asiaRepositoryItemComboBox = new RepositoryItemComboBox();

            this.asiaRepositoryItemComboBox.Items.Add("India");
            this.asiaRepositoryItemComboBox.Items.Add("Japan");
            this.asiaRepositoryItemComboBox.Items.Add("China");

            Load                             += Form_Load;
            this.treeList.CustomNodeCellEdit += treeList_CustomNodeCellEdit;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            this.treeList.RowHeight                              = 25;
            this.treeList.OptionsView.AutoWidth                  = false;
            this.treeList.OptionsBehavior.PopulateServiceColumns = true;
            this.treeList.KeyFieldName                           = "ID";
            this.treeList.ParentFieldName                        = "RegionID";

            this.treeList.DataSource = SalesData.GetSalesDataList();

            this.treeList.Columns[this.treeList.KeyFieldName   ].Visible = false;
            this.treeList.Columns[this.treeList.ParentFieldName].Visible = false;

            this.treeList.BestFitColumns();
        }

        #endregion
        #region 트리 리스트 노드 셀 에디터 커스텀 설정하기 - treeList_CustomNodeCellEdit(sender, e)

        /// <summary>
        /// 트리 리스트 노드 셀 에디터 커스텀 설정하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void treeList_CustomNodeCellEdit(object sender, GetCustomNodeCellEditEventArgs e)
        {
            if(e.Column.FieldName == "Region")
            {
                if(e.Node.Level == 0)
                {
                    e.RepositoryItem = this.repositoryItemComboBox;
                }
                else
                {
                    object cellValue = e.Node.ParentNode.GetValue("Region");

                    switch(cellValue.ToString())
                    {
                        case "Western Europe" : e.RepositoryItem = this.westernEuropeRepositoryItemComboBox; break;
                        case "Eastern Europe" : e.RepositoryItem = this.easternEuropeRepositoryItemComboBox; break;
                        case "North America"  : e.RepositoryItem = this.northAmericaRepositoryItemComboBox;  break;
                        case "South America"  : e.RepositoryItem = this.southAmericaRepositoryItemComboBox;  break;
                        case "Asia"           : e.RepositoryItem = this.asiaRepositoryItemComboBox;          break;
                    }
                }
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요