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

TestProject.zip
다운로드

▶ MainForm.cs

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

using DevExpress.XtraEditors;
using DevExpress.XtraVerticalGrid;
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;
            }

            this.gridControl.BestFit();

            this.gridControl.KeyDown += gridControl_KeyDown;
        }

        #endregion

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

        #region 그리드 컨트롤 키 DOWN 처리하기 - gridControl_KeyDown(sender, e)

        /// <summary>
        /// 그리드 컨트롤 키 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void gridControl_KeyDown(object sender, KeyEventArgs e)
        {
            VGridControl gridControl = sender as VGridControl;
            BaseRow      row         = gridControl.FocusedRow;
            BaseRow      previousRow = gridControl.GetPrevVisible(row);
            BaseRow      nextRow     = gridControl.GetNextVisible(row);

            if((e.KeyCode == Keys.Up) && e.Shift)
            {
                if((row == null) || (previousRow == null))
                {
                    return;
                }

                gridControl.MoveRow(row, previousRow, false);
            }

            if((e.KeyCode == Keys.Down) && e.Shift)
            {
                if((row == null) || (nextRow == null))
                {
                    return;
                }

                gridControl.MoveRow(nextRow, row, false);
            }
        }

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