■ PopupContainerEdit 클래스 : 다수 항목 선택하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

 

using DevExpress.XtraEditors;

using DevExpress.XtraEditors.Controls;

using DevExpress.XtraEditors.Repository;

using DevExpress.XtraGrid.Views.Grid;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            this.gridControl.DataSource       = GetCustomerList(5);

            this.popupGridControl1.DataSource = GetCustomerList(5);

            this.popupGridControl2.DataSource = GetCustomerList(5);

 

            #region 팝업 컨테이너 에디터를 설정한다.

 

            this.popupContainerEdit.Properties.PopupControl = this.popupContainerControl1;

 

            #endregion

            #region 팝업 컨테이너 컨트롤 2를 설정한다.

 

            PopupContainerControl popupContainerControl2 = new PopupContainerControl();

 

            popupContainerControl2.Size = new Size(500, 300);

 

            popupContainerControl2.Controls.Add(this.popupGridControl2);

 

            #endregion

            #region 저장소 항목 팝업 컨테이너 에디터를 설정한다.

 

            RepositoryItemPopupContainerEdit repositoryItemPopupContainerEdit = new RepositoryItemPopupContainerEdit();

 

            repositoryItemPopupContainerEdit.TextEditStyle = TextEditStyles.Standard;

            repositoryItemPopupContainerEdit.PopupControl  = popupContainerControl2;

 

            #endregion

            #region 그리드 뷰를 설정한다.

 

            this.gridView.Columns["Name"].ColumnEdit = repositoryItemPopupContainerEdit;

 

            #endregion

            #region 이벤트를 설정한다.

 

            repositoryItemPopupContainerEdit.QueryResultValue += repositoryItemPopupContainerEdit_QueryResultValue;

            repositoryItemPopupContainerEdit.EditValueChanged += repositoryItemPopupContainerEdit_EditValueChanged;

            repositoryItemPopupContainerEdit.Popup            += repositoryItemPopupContainerEdit_Popup;

 

            popupContainerEdit.Properties.QueryResultValue += popupContainerEdit_Properties_QueryResultValue;

            popupContainerEdit.Properties.EditValueChanged += popupContainerEdit_Properties_EditValueChanged;

            popupContainerEdit.Properties.Popup            += popupContainerEdit_Properties_Popup;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 저장소 항목 팝업 컨테이너 에디터 결과 값 질의하기 - repositoryItemPopupContainerEdit_QueryResultValue(sender, e)

 

        /// <summary>

        /// 저장소 항목 팝업 컨테이너 에디터 결과 값 질의하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void repositoryItemPopupContainerEdit_QueryResultValue(object sender, QueryResultValueEventArgs e)

        {

            int[] selectionArray = this.popupGridView2.GetSelectedRows();

 

            List<string> valueArray = new List<string>();

 

            foreach(int selection in selectionArray)

            {

                valueArray.Add(this.popupGridView2.GetRowCellValue(selection, "Name").ToString());

            }

 

            string resultValue = string.Join(", ", valueArray);

 

            e.Value = resultValue;

        }

 

        #endregion

        #region 저장소 항목 팝업 컨테이너 에디터 편집 값 변경시 처리하기 - repositoryItemPopupContainerEdit_EditValueChanged(sender, e)

 

        /// <summary>

        /// 저장소 항목 팝업 컨테이너 에디터 편집 값 변경시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void repositoryItemPopupContainerEdit_EditValueChanged(object sender, EventArgs e)

        {

            PopupContainerEdit popupContainerEdit = sender as PopupContainerEdit;

 

            if(!popupContainerEdit.IsPopupOpen)

            {

                popupContainerEdit.ShowPopup();

            }

 

            UpdateSelection(popupContainerEdit, this.popupGridView2);

        }

 

        #endregion

        #region 저장소 항목 팝업 컨테이너 에디터 팝업시 처리하기 - repositoryItemPopupContainerEdit_Popup(sender, e)

 

        /// <summary>

        /// 저장소 항목 팝업 컨테이너 에디터 팝업시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void repositoryItemPopupContainerEdit_Popup(object sender, EventArgs e)

        {

            PopupContainerEdit popupContainerEdit = sender as PopupContainerEdit;

 

            UpdateSelection(popupContainerEdit, this.popupGridView2);

        }

 

        #endregion

 

        #region 팝업 컨테이너 에디터 속성 결과 값 질의하기 - popupContainerEdit_Properties_QueryResultValue(sender, e)

 

        /// <summary>

        /// 팝업 컨테이너 에디터 속성 결과 값 질의하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void popupContainerEdit_Properties_QueryResultValue(object sender, QueryResultValueEventArgs e)

        {

            int[] selectionArray = this.popupGridView1.GetSelectedRows();

 

            List<string> valueList = new List<string>();

 

            foreach(int selection in selectionArray)

            {

                valueList.Add(this.popupGridView1.GetRowCellValue(selection, "Name").ToString());

            }

 

            string resultValue = string.Join(", ", valueList);

 

            e.Value = resultValue;

        }

 

        #endregion

        #region 팝업 컨테이너 에디터 속성 편집 값 변경시 처리하기 - popupContainerEdit_Properties_EditValueChanged(sender, e)

 

        /// <summary>

        /// 팝업 컨테이너 에디터 속성 편집 값 변경시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void popupContainerEdit_Properties_EditValueChanged(object sender, EventArgs e)

        {

            PopupContainerEdit popupContainerEdit = sender as PopupContainerEdit;

 

            UpdateSelection(popupContainerEdit, this.popupGridView1);

        }

 

        #endregion

        #region 팝업 컨테이너 에디터 속성 팝업시 처리하기 - popupContainerEdit_Properties_Popup(sender, e)

 

        /// <summary>

        /// 팝업 컨테이너 에디터 속성 팝업시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void popupContainerEdit_Properties_Popup(object sender, EventArgs e)

        {

            PopupContainerEdit popupContainerEdit = sender as PopupContainerEdit;

 

            if(!popupContainerEdit.IsPopupOpen)

            {

                popupContainerEdit.ShowPopup();

            }

 

            UpdateSelection(popupContainerEdit, this.popupGridView1);

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 선택 리스트 구하기 - GetSelectionList(valueArray, fieldName, gridView)

 

        /// <summary>

        /// 선택 리스트 구하기

        /// </summary>

        /// <param name="valueArray">값 배열</param>

        /// <param name="fieldName">필드명</param>

        /// <param name="gridView">그리드 뷰</param>

        /// <returns>선택 리스트</returns>

        private List<int> GetSelectionList(string[] valueArray, string fieldName, GridView gridView)

        {

            List<int> selectionList = new List<int>();

 

            foreach(string value in valueArray)

            {

                for(int i = 0; i < gridView.RowCount; i++)

                {

                    if(gridView.GetRowCellValue(i, fieldName).ToString() == value)

                    {

                        selectionList.Add(i);

                    }

                }

            }

 

            return selectionList;

        }

 

        #endregion

        #region 선택 업데이트하기 - UpdateSelection(popupContainerEdit, gridView)

 

        /// <summary>

        /// 선택 업데이트하기

        /// </summary>

        /// <param name="popupContainerEdit">팝업 컨테이너 에디터</param>

        /// <param name="gridView">그리드 뷰</param>

        private void UpdateSelection(PopupContainerEdit popupContainerEdit, GridView gridView)

        {

            gridView.BeginSelection();

 

            gridView.ClearSelection();

 

            if(popupContainerEdit != null)

            {

                if(popupContainerEdit.EditValue != null)

                {

                    popupContainerEdit.Focus();

 

                    List<int> selectionList = GetSelectionList

                    (

                        popupContainerEdit.EditValue.ToString().Split(new string[] { ", " }, StringSplitOptions.None),

                        "Name",

                        gridView

                    );

 

                    foreach(int selection in selectionList) {

 

                        gridView.SelectRow(selection);

                    }

                }

            }

 

            gridView.EndSelection();

        }

 

        #endregion

        #region 고객 리스트 구하기 - GetCustomerList(count)

 

        /// <summary>

        /// 고객 리스트 구하기

        /// </summary>

        /// <param name="count"></param>

        /// <returns>고객 리스트</returns>

        private BindingList<Customer> GetCustomerList(int count)

        {

            BindingList<Customer> list = new BindingList<Customer>();

 

            for(int i = 0; i < count; i++)

            {

                list.Add(new Customer(i, "성명" + i, "정보" + i));

            }

 

            return list;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요