■ CheckedComboBoxEdit 클래스 : 열거형 값 표시하기

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


TestProject.zip


ColorType.cs

 

 

using System;

 

namespace TestProject

{

    [Flags]

    public enum ColorType

    {

        /// <summary>

        /// 해당 무

        /// </summary>

        None = 0x00,

 

        /// <summary>

        /// 검정색

        /// </summary>

        Black = 0x01,

 

        /// <summary>

        /// 흰색

        /// </summary>

        White = 0x02,

 

        /// <summary>

        /// 파란색

        /// </summary>

        Blue = 0x04,

 

        /// <summary>

        /// 노란색

        /// </summary>

        Yellow = 0x08,

 

        /// <summary>

        /// 녹색

        /// </summary>

        Green = Blue | Yellow

    }

}

 

 

MainForm.cs

 

 

using System;

 

using DevExpress.XtraEditors;

using DevExpress.XtraEditors.Repository;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

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

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

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            this.checkedComboBoxEdit.Properties.SetFlags(typeof(ColorType));

 

            RemoveCombinedFlag(checkedComboBoxEdit.Properties);

 

            this.checkedComboBoxEdit.SetEditValue(ColorType.Black | ColorType.Green);

        }

 

        #endregion

 

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

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

 

        #region 결합 플래그 제거하기 - RemoveCombinedFlag(repositoryItemCheckedComboBoxEdit)

 

        /// <summary>

        /// 결합 플래그 제거하기

        /// </summary>

        /// <param name="repositoryItemCheckedComboBoxEdit">저장소 항목 체크 콤보 박스 에디터</param>

        private void RemoveCombinedFlag(RepositoryItemCheckedComboBoxEdit repositoryItemCheckedComboBoxEdit)

        {

            for(int i = repositoryItemCheckedComboBoxEdit.Items.Count - 1; i > 0; i--)

            {

                Enum value1 = repositoryItemCheckedComboBoxEdit.Items[i].Value as Enum;

 

                for(int j = i - 1; j >= 0; j--)

                {

                    Enum value2 = repositoryItemCheckedComboBoxEdit.Items[j].Value as Enum;

 

                    if(value1.HasFlag(value2))

                    {

                        repositoryItemCheckedComboBoxEdit.Items.RemoveAt(i);

 

                        break;

                    }

                }

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요