DevExpress&UI

Devexpress GridView 팁 1

Code GGOON 2019. 3. 18. 08:17
반응형

 

GridView 를 사용하다 보면 Cell 들을 Merge할 때가 발생합니다.

따라서, Cell Merge하는 방법은 아래와 같이 할 수 있습니다.

 

1. 세로 Merge

GridView.OptionsView.AllowCellMerge = true;

이와 같이 옵션을 설정하면, 기본적으로 Column 단위로 같은 Value 값을 가지는 Cell 단위로 Merge를 합니다.

 

GridColumn.OptionsColumn.AllowMerge = false;

이와 같이 할경우 해당 Column은 Merge를 실행하지 않습니다.

 

GridView.CellMerge Event를 통해 사용자 조건별로 Merge를 할 수 있습니다

void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
{
    if (e.Column.FieldName == "Q'TY")
    {
        int iValue1 = Convert.ToInt32(e.CellValue1);
        int iValue2 = Convert.ToInt32(e.CellValue2);
        e.Merge = true;
        e.Handled = true;
    }
}

 

2. 가로 Merge

가로 Merge 같은 경우는 GridView에서 옵션으로 기본 제공하지 않습니다.

따라서 해당 Cell을 강제적으로 다시 그려주는 등 여러 가지 Event를 사용해야 합니다.

따라서 Devexpress 에서 예제로 나오 있는 곳을 링크하는 것으로 대신합니다.

 

Merge cells Horizontally in GridView

https://www.devexpress.com/Support/Center/Example/Details/E2472/how-to-merge-cells-horizontally-in-gridview

 

==================

[ROW Cell Sum Exam 1]

 

using DevExpress.XtraGrid.Views.Base; 
using DevExpress.XtraGrid.Views.Grid; 
using DevExpress.XtraGrid.Columns; 

private void Form1_Load(object sender, System.EventArgs e) 
{ 
    // ... gridControl1.ForceInitialize(); 
    // Create an unbound column. 
    GridColumn unbColumn = gridView1.Columns.AddField("Total"); 
    unbColumn.VisibleIndex = gridView1.Columns.Count; 
    unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; 
    
    // Disable editing. 
    unbColumn.OptionsColumn.AllowEdit = false; 
    // Specify format settings. 
    unbColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; 
    unbColumn.DisplayFormat.FormatString = "c"; 
    
    // Customize the appearance settings. 
    unbColumn.AppearanceCell.BackColor = Color.LemonChiffon;
} 

// Returns the total amount for a specific row. 
decimal getTotalValue(GridView view, int listSourceRowIndex) 
{
	decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "UnitPrice"));
    decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Quantity")); 
    decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(listSourceRowIndex, "Discount")); 
    
    return unitPrice * quantity * (1 - discount); 
}

// Provides data for the Total column. 
private void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e)
{ 
	GridView view = sender as GridView; 
    
    if (e.Column.FieldName == "Total" && e.IsGetData) 
    	e.Value = getTotalValue(view, e.ListSourceRowIndex);
}

================

 

[Link]

https://documentation.devexpress.com/WindowsForms/1477/Controls-and-Libraries/Data-Grid/Unbound-Columns

반응형