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

TestProject.zip
다운로드

▶ CountRowOperation.cs

using DevExpress.XtraVerticalGrid.Rows;

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

        #region Field

        /// <summary>
        /// 전체 행 카운트
        /// </summary>
        private int totalRowCount;

        #endregion

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

        #region 전체 행 카운트 - TotalRowCount

        /// <summary>
        /// 전체 행 카운트
        /// </summary>
        public int TotalRowCount
        {
            get
            {
                return this.totalRowCount;
            }
        }

        #endregion

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

        #region 생성자 - CountRowOperation()

        /// <summary>
        /// 생성자
        /// </summary>
        public CountRowOperation() : base()
        {
            this.totalRowCount = 0;
        }

        #endregion

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

        #region 실행하기 - Execute(row)

        /// <summary>
        /// 실행하기
        /// </summary>
        /// <param name="row">행</param>
        public override void Execute(BaseRow row)
        {
            this.totalRowCount++;
        }

        #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();

            this.gridControl.RowsIterator.DoOperation(operation);

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

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