본문 바로가기
develop

DevExpress XtraGrid Custom Merge

by 파드 2020. 4. 8.
반응형

그리드에서 아래 표처럼 COL3 에서 9에서 7전까지를 MERGE 하고 싶었음.

쿼리로 동일 숫자 나오게 해서 그리드 자체 기능의 AUTOMERGE를 사용해도 되나, Footer에 합계를 넣어야 했기에

이방법은 패스.

그래서 merge 이벤트를 사용하여 내가 원하는 조건일때 merge 되게 하는 방법으로 해결.

 

COL1 COL2 COL3
a g 9
b h  
c i  
d j 7
e k  
f l  
    합계 16

 

출처: https://documentation.devexpress.com/WindowsForms/114730/Controls-and-Libraries/Data-Grid/Get-Started-With-Data-Grid-and-Views/Walkthroughs/Grid-View-Columns-Rows-and-Cells/Tutorial-Cell-Merging

 

C# using DevExpress.XtraGrid.Views.Grid; // ... 

 

private void grvMain_CellMerge(object sender, CellMergeEventArgs e)
{
   GridView view = sender as GridView;
   if (view == null) return;
   if (e.Column.FieldName == "CNT")
   {
      string text1 = view.GetRowCellDisplayText(e.RowHandle1, "CNT");
      string text2 = view.GetRowCellDisplayText(e.RowHandle2, "CNT");
      if (text1 == string.Empty && text2 == string.Empty)
      {
         e.Merge = (text1 == text2);
         e.Handled = true;
      }
   }
}

 

반응형