[DEVEXPRESS/WINFORM] VGridControl 클래스 : CustomUnboundData 이벤트를 사용해 언바운드 데이터 커스텀 설정하기
DevExpress/WinForm 2020. 4. 26. 19:31728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Data;
using System.Drawing;
using DevExpress.Data;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Events;
using DevExpress.XtraVerticalGrid.Rows;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 전체 행
/// </summary>
private EditorRow totalRow = null;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.gridControl.DataSource = new nwindDataSetTableAdapters.Order_DetailsTableAdapter().GetData();
foreach(EditorRow row in this.gridControl.Rows)
{
row.Properties.AllowEdit = true;
}
this.totalRow = new EditorRow();
this.totalRow.Properties.FieldName = "Total";
this.totalRow.Properties.Caption = "Total";
this.totalRow.Properties.Format.FormatType = FormatType.Numeric;
this.totalRow.Properties.Format.FormatString = "c";
this.totalRow.Properties.ImageIndex = 1;
this.totalRow.Properties.ReadOnly = true;
this.totalRow.Properties.UnboundType = UnboundColumnType.Decimal;
this.totalRow.Appearance.BackColor = Color.LightYellow;
this.totalRow.Appearance.Font = new Font(this.totalRow.Appearance.Font, FontStyle.Bold);
this.gridControl.Rows.Add(this.totalRow);
this.gridControl.CustomUnboundData += gridControl_CustomUnboundData;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 그리드 컨트롤 언바운드 데이터 커스텀 설정하기 - gridControl_CustomUnboundData(sender, e)
/// <summary>
/// 그리드 컨트롤 언바운드 데이터 커스텀 설정하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void gridControl_CustomUnboundData(object sender, CustomDataEventArgs e)
{
VGridControl gridControl = sender as VGridControl;
if(e.Row == this.totalRow && e.IsGetData)
{
DataRowView dataRowView = (DataRowView)gridControl.GetRecordObject(e.ListSourceRowIndex);
decimal unitPrice = Convert.ToDecimal(dataRowView["UnitPrice"]);
decimal quantity = Convert.ToDecimal(dataRowView["Quantity" ]);
decimal discount = Convert.ToDecimal(dataRowView["Discount" ]);
e.Value = unitPrice * quantity * (1 - discount);
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요