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

TestProject.zip
다운로드

▶ CountRowOperation.cs

using System.Collections.Generic;

using DevExpress.XtraVerticalGrid.Rows;

namespace TestProject
{
    /// <summary>
    /// 행 카운트 작업
    /// </summary>
    public class CountRowOperation : RowOperation
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 레벨
        /// </summary>
        private int level;

        /// <summary>
        /// 행 리스트
        /// </summary>
        private List<BaseRow> rowList;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 행 리스트 - RowList

        /// <summary>
        /// 행 리스트
        /// </summary>
        public List<BaseRow> RowList
        {
            get
            {
                return this.rowList;
            }
        }

        #endregion

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

        #region 생성자 - CountRowOperation(level)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="level">레벨</param>
        public CountRowOperation(int level) : base()
        {
            this.level = level;

            this.rowList = new List<BaseRow>();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 자식 행 방문 필요 여부 구하기 - NeedsVisitChildren(row)

        /// <summary>
        /// 자식 행 방문 필요 여부 구하기
        /// </summary>
        /// <param name="row">행</param>
        /// <returns>자식 행 방문 필요 여부</returns>
        public override bool NeedsVisitChildren(BaseRow row)
        {
            if(row.Level == level) 
            {
                return false;
            }

            return true;
        }

        #endregion
        #region 실행하기 - Execute(row)

        /// <summary>
        /// 실행하기
        /// </summary>
        /// <param name="row">행</param>
        public override void Execute(BaseRow row)
        {
            if(row.Level == level)
            {
                this.rowList.Add(row);
            }
         }

        #endregion
    }
}

 

728x90

 

▶ MainForm.cs

using System;
using System.Data.OleDb;
using System.Windows.Forms;

using DevExpress.XtraEditors;
using DevExpress.XtraVerticalGrid.Rows;

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

        #region Field

        /// <summary>
        /// 연결
        /// </summary>
        private OleDbConnection connection;

        #endregion

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

        #region 생성자 - MainForm()

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

            this.connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=nwind.mdb");

            this.gridControl.DataSource = Order.GetOrderList(this.connection);

            foreach(EditorRow row in this.gridControl.Rows)
            {
                row.Properties.AllowEdit = false;
            }

            EditorRow shipNameRow       = this.gridControl.Rows["rowShipName"      ] as EditorRow;
            EditorRow shipAddressRow    = this.gridControl.Rows["rowShipAddress"   ] as EditorRow;
            EditorRow shipCityRow       = this.gridControl.Rows["rowShipCity"      ] as EditorRow;
            EditorRow shipRegionRow     = this.gridControl.Rows["rowShipRegion"    ] as EditorRow;
            EditorRow shipPostalCodeRow = this.gridControl.Rows["rowShipPostalCode"] as EditorRow;
            EditorRow shipCountryRow    = this.gridControl.Rows["rowShipCountry"   ] as EditorRow;

            this.gridControl.MoveRow(shipAddressRow   , shipNameRow, false);
            this.gridControl.MoveRow(shipCityRow      , shipNameRow, false);
            this.gridControl.MoveRow(shipRegionRow    , shipNameRow, false);
            this.gridControl.MoveRow(shipPostalCodeRow, shipNameRow, false);
            this.gridControl.MoveRow(shipCountryRow   , shipNameRow, false);

            this.gridControl.BestFit();

            Shown += Form_Shown;
        }

        #endregion

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

        #region 폼 표시 후 처리하기 - Form_Shown(sender, e)

        /// <summary>
        /// 폼 표시 후 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Shown(object sender, EventArgs e)
        {
            CountRowOperation operation = new CountRowOperation(1);

            this.gridControl.RowsIterator.DoOperation(operation);

            XtraMessageBox.Show
            (
                this,
                $"행 수 : {operation.RowList.Count.ToString()}",
                "INFORMATION",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information
            );
        }

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

댓글을 달아 주세요