Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom cell merged

I need to display data in gridview with merged rows for some columns. the original data from database like:

enter image description here

please help me to display gridview like:

enter image description here

  • for column transaksi merged by tgl
  • for column priority , price , creted by merged by transaksi

Using C#, how can I prepare a gridview for the format? Please help me.

like image 972
manggaraaaa Avatar asked Jan 18 '26 09:01

manggaraaaa


1 Answers

I suggest you to go through documentation - Tutorial: Cell Merging

To implement custom cell merge use the GridView.CellMerge event handler. First, check if the correct column is being processed. Then, obtain display texts for the two cells being compared. Finally, indicate that cells are to be merged if their display texts match. Set the CellMergeEventArgs.Handled parameter to true to override the grid's default processing for this column.

Example:

using DevExpress.XtraGrid.Views.Grid;
// ... 
private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e) {
    GridView view = sender as GridView;
    if(view == null) return;
    if (e.Column == colCreatorID) {
        string text1 = view.GetRowCellDisplayText(e.RowHandle1, colCreatorID);
        string text2 = view.GetRowCellDisplayText(e.RowHandle2, colCreatorID);
        e.Merge = (text1 == text2);
        e.Handled = true;
    }
}

Use your own conditions while processing a column. for example take transaksi 005, In this case check values of row 5 and 6 then compare column created by for equality depends upon your condition set the e.Merge to true.

like image 71
Niranjan Singh Avatar answered Jan 20 '26 00:01

Niranjan Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!