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

TestProject.zip
다운로드

▶ MainForm.cs

using System.Windows.Forms;

using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;

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

        #region Field

        /// <summary>
        /// 타입 1 값 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox type1ValueRepositoryItemComboBox;

        /// <summary>
        /// 타입 2 값 저장소 항목 콤보 박스
        /// </summary>
        private RepositoryItemComboBox type2ValueRepositoryItemComboBox;

        #endregion

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

        #region 생성자 - MainForm()

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

            #region 타입 저장소 항목 콤보 박스를 설정한다.

            RepositoryItemComboBox typeRepositoryItemComboBox = new RepositoryItemComboBox();

            typeRepositoryItemComboBox.TextEditStyle           = TextEditStyles.DisableTextEditor;
            typeRepositoryItemComboBox.AppearanceDropDown.Font = Font;

            typeRepositoryItemComboBox.Items.Add("타입 1");
            typeRepositoryItemComboBox.Items.Add("타입 2");

            #endregion
            #region 타입 1 값 저장소 항목 콤보 박스를 설정한다. 

            this.type1ValueRepositoryItemComboBox = new RepositoryItemComboBox();

            this.type1ValueRepositoryItemComboBox.TextEditStyle           = TextEditStyles.DisableTextEditor;
            this.type1ValueRepositoryItemComboBox.AppearanceDropDown.Font = Font;

            this.type1ValueRepositoryItemComboBox.Items.Add(""           );
            this.type1ValueRepositoryItemComboBox.Items.Add("타입 1 값 1");
            this.type1ValueRepositoryItemComboBox.Items.Add("타입 1 값 2");
            this.type1ValueRepositoryItemComboBox.Items.Add("타입 1 값 3");

            #endregion
            #region 타입 2 값 저장소 항목 콤보 박스를 설정한다.

            this.type2ValueRepositoryItemComboBox = new RepositoryItemComboBox();

            this.type2ValueRepositoryItemComboBox.TextEditStyle           = TextEditStyles.DisableTextEditor;
            this.type2ValueRepositoryItemComboBox.AppearanceDropDown.Font = Font;

            this.type2ValueRepositoryItemComboBox.Items.Add(""           );
            this.type2ValueRepositoryItemComboBox.Items.Add("타입 2 값 1");
            this.type2ValueRepositoryItemComboBox.Items.Add("타입 2 값 2");
            this.type2ValueRepositoryItemComboBox.Items.Add("타입 2 값 3");

            #endregion
            #region 그리드 뷰를 초기화 한다.

            this.gridView.OptionsDetail.EnableMasterViewMode = false;
            this.gridView.OptionsSelection.MultiSelect       = true;
            this.gridView.OptionsSelection.MultiSelectMode   = GridMultiSelectMode.CellSelect;
            this.gridView.FocusRectStyle                     = DrawFocusRectStyle.CellFocus;

            // 그룹 패널
            this.gridView.OptionsView.ShowGroupPanel = false;

            // 행
            this.gridView.IndicatorWidth                         = 30;
            this.gridView.OptionsView.ShowIndicator              = true;
            this.gridView.OptionsView.EnableAppearanceEvenRow    = false;
            this.gridView.OptionsView.EnableAppearanceOddRow     = false;
            this.gridView.OptionsBehavior.KeepFocusedRowOnUpdate = false;
            this.gridView.OptionsNavigation.AutoFocusNewRow      = true;

            // 컬럼
            this.gridView.OptionsBehavior.AutoPopulateColumns      = false;
            this.gridView.OptionsView.ShowColumnHeaders            = true;
            this.gridView.OptionsView.ColumnAutoWidth              = false;
            this.gridView.OptionsMenu.EnableColumnMenu             = false;
            this.gridView.OptionsNavigation.EnterMoveNextColumn    = true;
            this.gridView.OptionsCustomization.AllowColumnMoving   = true;
            this.gridView.OptionsCustomization.AllowColumnResizing = true;
            this.gridView.OptionsCustomization.AllowFilter         = false;
            this.gridView.OptionsCustomization.AllowSort           = true;

            // 셀
            this.gridView.OptionsView.ShowButtonMode                   = ShowButtonModeEnum.ShowForFocusedCell;
            this.gridView.OptionsView.AllowCellMerge                   = false;
            this.gridView.OptionsBehavior.EditorShowMode               = EditorShowMode.MouseDown;
            this.gridView.OptionsBehavior.Editable                     = true;
            this.gridView.OptionsSelection.EnableAppearanceFocusedCell = true;
            this.gridView.OptionsSelection.InvertSelection             = false;
            this.gridView.OptionsHint.ShowCellHints                    = false;
            this.gridView.OptionsClipboard.CopyColumnHeaders           = DefaultBoolean.False;

            // 모양
            this.gridView.Appearance.Row.Font         = Font;
            this.gridView.Appearance.HeaderPanel.Font = Font;

            GridColumn typeColumn = this.gridView.Columns.AddVisible("Type", "타입");

            typeColumn.Name                                    = "Type";
            typeColumn.Width                                   = 100;
            typeColumn.AppearanceHeader.Options.UseTextOptions = true;
            typeColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            typeColumn.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center;
            typeColumn.AppearanceCell.Options.UseTextOptions   = true;
            typeColumn.AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Near;
            typeColumn.AppearanceCell.TextOptions.VAlignment   = VertAlignment.Center;
            typeColumn.OptionsColumn.AllowEdit                 = true;
            typeColumn.ColumnEdit                              = typeRepositoryItemComboBox;

            GridColumn valueColumn = this.gridView.Columns.AddVisible("Value", "값");

            valueColumn.Name                                    = "Value";
            valueColumn.Width                                   = 200;
            valueColumn.AppearanceHeader.Options.UseTextOptions = true;
            valueColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            valueColumn.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center;
            valueColumn.AppearanceCell.Options.UseTextOptions   = true;
            valueColumn.AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Near;
            valueColumn.AppearanceCell.TextOptions.VAlignment   = VertAlignment.Center;
            valueColumn.OptionsColumn.AllowEdit                 = true;
            valueColumn.ColumnEdit                              = null;

            #endregion
            #region 이벤트를 설정한다.

            this.gridView.CustomRowCellEdit += gridView_CustomRowCellEdit;

            #endregion

            this.gridControl.DataSource = Item.GetList();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 그리드 뷰 커스텀 행/셀 편집시 처리하기 - gridView_CustomRowCellEdit(sender, e)

        /// <summary>
        /// 그리드 뷰 커스텀 행/셀 편집시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void gridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
        {
            GridView gridView = sender as GridView;

            if(e.Column.FieldName == nameof(Item.Value))
            {
                Item item = gridView.GetRow(e.RowHandle) as Item;

                if(item.Type == "타입 1")
                {
                    e.RepositoryItem = this.type1ValueRepositoryItemComboBox;  
                }
                else if(item.Type == "타입 2")
                {
                    e.RepositoryItem = this.type2ValueRepositoryItemComboBox;
                }
            }
        }

        #endregion
    }
}

 

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요