반응형
1. 데이터 조회 결과
2. Row Cell 머지
view.OptionsView.AllowCellMerge = true;
//Row Cell Merge
view.CellMerge += (sen, e) =>
{
GridView view2 = sen as GridView;
if (e.Column.FieldName == "CAR_TYPE")
{
string val_1 = view.GetRowCellDisplayText(e.RowHandle1, view2.Columns["CAR_TYPE"]);
string val_1_1 = view.GetRowCellDisplayText(e.RowHandle1, view2.Columns["DATA_CLASS"]);
string val_2 = view.GetRowCellDisplayText(e.RowHandle2, view2.Columns["CAR_TYPE"]);
string val_2_1 = view.GetRowCellDisplayText(e.RowHandle1, view2.Columns["DATA_CLASS"]);
// 컬럼의 값이 모두 같을 경우에 조건이 충족할때
e.Merge = val_1 == val_2 && val_1_1.IsNullOrWhiteSpace() == false && val_1_1.IsNullOrWhiteSpace() == false;
e.Handled = true;
}
};
3. Column Cell 머지
//Column Cell Merge
view.CustomDrawCell += (sen, e) =>
{
GridView view2 = sen as GridView;
if (e.Column.FieldName == "CAR_TYPE" )
{
int rowHandle = e.RowHandle;
string carTypeValue = view2.GetRowCellValue(rowHandle, "CAR_TYPE")?.ToString();
string dataClassValue = view2.GetRowCellValue(rowHandle, "DATA_CLASS")?.ToString();
if (!string.IsNullOrWhiteSpace(carTypeValue) && string.IsNullOrWhiteSpace(dataClassValue))
{
{
try
{
//라인제거
if (((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo)(e.Cell)).LineCount == 2)
((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo)(e.Cell)).Lines.Remove(((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo)(e.Cell)).Lines[0]);
}
catch (Exception)
{
}
//2개Cell 더해서 그리기
Rectangle rect = e.Bounds;
rect.Width += e.Bounds.Width;
e.Graphics.FillRectangle(new SolidBrush(Color.Transparent), rect);
e.Graphics.DrawString(carTypeValue, e.Appearance.Font, new SolidBrush(e.Appearance.ForeColor), rect, e.Appearance.GetStringFormat());
e.Handled = true;
}
}
}
};
4. 결과
sample.cs
0.00MB