devexpress report 合併列具有重複值的單元格

小石头的一天發表於2024-10-17

使用場景,分組統計產品數量 ,產品列每行都會重複出現相同的產品名,於是把此列所有相同內容的行的單元格合併成一個單元格,一些人覺得這樣看的方便.

不讀文件一頭霧水,試了很多次都沒效果,看了文件發現非常簡單.

demo例子中沒有,在官網中找到一個案例

https://docs.devexpress.com/XtraReports/120027/detailed-guide-to-devexpress-reporting/use-report-controls/use-tables/manipulate-table-elements

https://github.com/DevExpress-Examples/reporting-winforms-process-duplicate-values/blob/23.1.2%2B/Images/screenshot.gif

public void NoMerge()
            {
                this.ShowPreviewDialog();
            }
            // Merge duplicate values of the XRControl.Tag property.
            public void MergeByTag()
            {
                ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "Tag", "ToStr([SupplierID]) + '_' + ToStr([CategoryID])");
                this.xrTableCell2.ExpressionBindings.Add(expressionBinding);
                this.xrTableCell2.ProcessDuplicatesMode = ProcessDuplicatesMode.Merge;
                this.xrTableCell2.ProcessDuplicatesTarget = DevExpress.XtraReports.UI.ProcessDuplicatesTarget.Tag;
                this.ShowPreviewDialog();
            }
            // Merge duplicate values of a report control's data.
            public void MergeByValue()
            {
                ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "Text", "[CategoryName]");
                this.xrTableCell2.ExpressionBindings.Add(expressionBinding);
                this.xrTableCell2.ProcessDuplicatesMode = ProcessDuplicatesMode.Merge;
                this.xrTableCell2.ProcessDuplicatesTarget = DevExpress.XtraReports.UI.ProcessDuplicatesTarget.Value;
                this.ShowPreviewDialog();
            }

demo內是程式碼實現的 ,這可能與你的專案展示不太一樣.

而簡單的方式是,右鍵單元格屬性

ProcessDuplicatesMode = ProcessDuplicatesMode.Merge;

相關文章