[DEVEXPRESS/WINFORM] VGridControl 클래스 : MoveRow 메소드를 사용해 중첩 행 만들기
DevExpress/WinForm 2020. 4. 26. 20:47728x90
728x170
▶ 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
그리드형(광고전용)