原創(chuàng)|其它|編輯:郝浩|2012-09-19 14:48:28.000|閱讀 1231 次
概述:本教程描述了DevExpress報(bào)表控件XtraReports創(chuàng)建穿透鉆取報(bào)表的步驟,其中詳細(xì)報(bào)表類(lèi)別可以通過(guò)單擊在新窗口中調(diào)用,讓您避免原報(bào)表中的兀余信息。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
本教程描述了DevExpress報(bào)表控件XtraReports創(chuàng)建穿透鉆取報(bào)表的步驟,其中詳細(xì)報(bào)表類(lèi)別可以通過(guò)單擊在新窗口中調(diào)用,讓您避免原報(bào)表中的兀余信息。
步驟如下:
1、 打開(kāi)MS Visual Studio(2008或2010),并在任何受支持的平臺(tái)上創(chuàng)建一個(gè)新的應(yīng)用程序,或者打開(kāi)一個(gè)已有的應(yīng)用程序。
2、 添加一個(gè)新的空白報(bào)表(名為MasterReport),并將該報(bào)表綁定到示例Northwind數(shù)據(jù)庫(kù)(XtraReports安裝包中附帶的nwind.mdb文檔)的"Categories" 標(biāo)簽上。
3、 從Field List字段列表,把CategoryName數(shù)據(jù)字段拖到報(bào)表的Detail band細(xì)節(jié)區(qū)域中,自動(dòng)創(chuàng)建一個(gè)數(shù)據(jù)綁定控件。
4、 添加另一個(gè)空白報(bào)表(名為DetailReport),并將它綁定到Northwind數(shù)據(jù)庫(kù)的"Products"標(biāo)簽上。
5、 為報(bào)表添加參數(shù),在Field List字段列表中,右鍵單擊并選擇Parameters部分,并選擇Add Parameters。
6、 通過(guò)這種方式,創(chuàng)建兩個(gè)參數(shù),命名為catId和catName。設(shè)置他們的Modifiers修飾符屬性為Public、并為catId參數(shù)設(shè)置Parameter.Type屬性為Int32。
7、 創(chuàng)建一個(gè)ReportHeaderBand……
并且,從Field List字段列表,把catName參數(shù)拖放到到創(chuàng)建區(qū)域上。
8、 然后,為報(bào)表添加GroupHeaderBand。創(chuàng)建一個(gè)報(bào)表代表 "Products" 數(shù)據(jù)表中的數(shù)據(jù)。
DetailReport報(bào)表最終應(yīng)該如下圖所示。
9、 設(shè)置報(bào)表的的XtraReportXtraReport.RequestParameters屬性為false,單擊省略號(hào)按鈕,為XtraReportBase.FilterString屬性調(diào)用FilterString編輯器。
10、 使用編輯器,定義以下表達(dá)式: [CategoryID] = [Parameters.catId]。
11、 切換回MasterReport,為創(chuàng)建的標(biāo)簽控件,處理以下事件:XRControl.BeforePrint, XRControl.PreviewClick和XRControl.PreviewMouseMove。
12、 為這些事件處理程序引用以下代碼。
注意,控件的XRControl.Tag屬性用于存儲(chǔ)當(dāng)前數(shù)據(jù)字段的值。
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
穿透鉆取報(bào)表就完成了。運(yùn)行打印預(yù)覽表單,并查看結(jié)果。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)