原創|其它|編輯:郝浩|2012-09-19 14:48:28.000|閱讀 1231 次
概述:本教程描述了DevExpress報表控件XtraReports創建穿透鉆取報表的步驟,其中詳細報表類別可以通過單擊在新窗口中調用,讓您避免原報表中的兀余信息。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本教程描述了DevExpress報表控件XtraReports創建穿透鉆取報表的步驟,其中詳細報表類別可以通過單擊在新窗口中調用,讓您避免原報表中的兀余信息。
步驟如下:
1、 打開MS Visual Studio(2008或2010),并在任何受支持的平臺上創建一個新的應用程序,或者打開一個已有的應用程序。
2、 添加一個新的空白報表(名為MasterReport),并將該報表綁定到示例Northwind數據庫(XtraReports安裝包中附帶的nwind.mdb文檔)的"Categories" 標簽上。
3、 從Field List字段列表,把CategoryName數據字段拖到報表的Detail band細節區域中,自動創建一個數據綁定控件。
4、 添加另一個空白報表(名為DetailReport),并將它綁定到Northwind數據庫的"Products"標簽上。
5、 為報表添加參數,在Field List字段列表中,右鍵單擊并選擇Parameters部分,并選擇Add Parameters。
6、 通過這種方式,創建兩個參數,命名為catId和catName。設置他們的Modifiers修飾符屬性為Public、并為catId參數設置Parameter.Type屬性為Int32。
7、 創建一個ReportHeaderBand……
并且,從Field List字段列表,把catName參數拖放到到創建區域上。
8、 然后,為報表添加GroupHeaderBand。創建一個報表代表 "Products" 數據表中的數據。
DetailReport報表最終應該如下圖所示。
9、 設置報表的的XtraReportXtraReport.RequestParameters屬性為false,單擊省略號按鈕,為XtraReportBase.FilterString屬性調用FilterString編輯器。
10、 使用編輯器,定義以下表達式: [CategoryID] = [Parameters.catId]。
11、 切換回MasterReport,為創建的標簽控件,處理以下事件:XRControl.BeforePrint, XRControl.PreviewClick和XRControl.PreviewMouseMove。
12、 為這些事件處理程序引用以下代碼。
注意,控件的XRControl.Tag屬性用于存儲當前數據字段的值。
C#
using System.Data;
using System.Windows.Forms;
using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
// ...
// Save the data for the current category to the label's Tag property.
private void xrLabel1_BeforePrint(object sender, PrintEventArgs e) {
((XRLabel)sender).Tag = GetCurrentRow();
}
private void xrLabel1_PreviewClick(object sender, PreviewMouseEventArgs e) {
// Create a new Detail Report instance.
DetailReport detailReport = new DetailReport();
// Obtain the current category's ID and Name from the e.Brick.Value property,
// which stores an object assigned the label's Tag property.
detailReport.catId.Value = (int)((DataRowView)e.Brick.Value).Row["CategoryID"];
detailReport.catName.Value = ((DataRowView)e.Brick.Value).Row["CategoryName"].ToString();
// Show the detail report in a new modal window.
detailReport.ShowPreviewDialog();
}
// The following code changes the cursor to "hand" when it hovers the label,
// so that it behaves as a common link.
private void xrLabel1_PreviewMouseMove(object sender, PreviewMouseEventArgs e) {
Cursor.Current = Cursors.Hand;
}
VB
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports DevExpress.XtraReports.UI
' ...
' Save the data for the current category to the label's Tag property.
Private Sub xrLabel1_BeforePrint(ByVal sender As Object, ByVal e _
As PrintEventArgs) Handles xrLabel1.BeforePrint
CType(sender, XRLabel).Tag = GetCurrentRow()
End Sub
Private Sub xrLabel1_PreviewClick(ByVal sender As Object, ByVal e _
As PreviewMouseEventArgs) Handles xrLabel1.PreviewClick
' Create a new Detail Report instance.
Dim detailReport As New DetailReport()
' Obtain the current category's ID and Name from the e.Brick.Value property,
' which stores an object assigned the label's Tag property.
detailReport.catId.Value = CInt(Fix((CType(e.Brick.Value, DataRowView)).Row("CategoryID")))
detailReport.catName.Value = (CType(e.Brick.Value, DataRowView)).Row("CategoryName").ToString()
' Show the detail report in a new modal window.
detailReport.ShowPreviewDialog()
End Sub
' The following code changes the cursor to "hand" when it hovers the label,
' so that it behaves as a common link.
Private Sub xrLabel1_PreviewMouseMove(ByVal sender As Object, ByVal e _
As PreviewMouseEventArgs) Handles xrLabel1.PreviewMouseMove
Cursor.Current = Cursors.Hand
End Sub
穿透鉆取報表就完成了。運行打印預覽表單,并查看結果。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網