原創|其它|編輯:郝浩|2012-09-18 11:43:12.000|閱讀 686 次
概述:本教程描述了創建drill-down report鉆取報表的步驟。在這個例子中,我們將用到使用Detail Report bands細節報表區域創建的master-detail report主從報表,每個類別的細節部分可以通過點擊一個適當的鏈接展開/折疊。附上圖片和代碼說明。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本教程描述了運用DevExpress XtraReports創建drill-down report鉆取報表的步驟。在這個例子中,我們將用到使用Detail Report bands細節報表區域創建的master-detail report主從報表,每個類別的細節部分可以通過點擊一個適當的鏈接展開/折疊。
步驟如下:
1 使用Detail Report區域創建一個master-detail report主從復合結構報表。
2 創建一個顯示/隱藏細節報表的鏈接,將標簽拖放到報表的Detail細節區域上。
設置XRControl.Text的文本為Show Detail, XRControl.Name名稱為lblShowHide,并設置 (DataBindings)Tag.Binding屬性為CategoryID數據字段.
3 執行上述步驟后,可以得到如下報表。
4然后以如下的編程方式處理標簽的BeforePrint,PreviewClick,PreviewMouseMove事件和DetailReport的BeforePrint事件:
C#
using System.Collections;
using System.Windows.Forms;
using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
// ...
// Declare two string constants, to store the label's Text value.
const string sShowDetail = "Show Detail";
const string sHideDetail = "Hide Detail";
// Create an array containing IDs of the categories being expanded.
ArrayList expandedValues = new ArrayList();
// This function returns a value indicating whether a certain
// category's details should be expanded.
bool ShouldShowDetail(int catID) {
return expandedValues.Contains(catID);
}
private void lbShowHide_BeforePrint(object sender, PrintEventArgs e) {
XRLabel label = (XRLabel)sender;
// Choose the label's text.
if(ShouldShowDetail((int)label.Tag)) {
label.Text = sHideDetail;
}
else {
label.Text = sShowDetail;
}
}
private void DetailReport_BeforePrint(object sender, PrintEventArgs e) {
// Cancel the Detail Report band's printing if necessary.
e.Cancel = !ShouldShowDetail((int)GetCurrentColumnValue("CategoryID"));
}
private void lbShowHide_PreviewClick(object sender, PreviewMouseEventArgs e) {
// Obtain the category's ID stored in the label's Tag property.
int index = (int)e.Brick.Value;
// Determine whether the current category's details are shown.
bool showDetail = ShouldShowDetail(index);
// Toggle the visibility of the category's details.
if(showDetail) {
expandedValues.Remove(index);
}
else {
expandedValues.Add(index);
}
// Re-create a document to apply the changes.
CreateDocument();
}
// The following code changes the cursor to "hand" when it hovers the label,
// so that it behaves as a common link.
private void lbShowHide_PreviewMouseMove(object sender, PreviewMouseEventArgs e) {
Cursor.Current = Cursors.Hand;
}
VB
Imports System.Collections
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports DevExpress.XtraReports.UI
' ...
' Declare two string constants, to store the label's Text value.
Private Const sShowDetail As String = "Show Detail"
Private Const sHideDetail As String = "Hide Detail"
' Create an array containing IDs of the categories being expanded.
Private expandedValues As New ArrayList()
' This function returns a value indicating whether a certain
' category's details should be expanded.
Private Function ShouldShowDetail(ByVal catID As Integer) As Boolean
Return expandedValues.Contains(catID)
End Function
Private Sub lbShowHide_BeforePrint(ByVal sender As Object, ByVal e _
As PrintEventArgs) Handles lbShowHide.BeforePrint
Dim label As XRLabel = CType(sender, XRLabel)
' Choose the label's text.
If ShouldShowDetail(CInt(Fix(label.Tag))) Then
label.Text = sHideDetail
Else
label.Text = sShowDetail
End If
End Sub
Private Sub DetailReport_BeforePrint(ByVal sender As Object, ByVal e _
As PrintEventArgs) Handles DetailReport.BeforePrint
' Cancel the Detail Report band's printing if necessary.
e.Cancel = Not ShouldShowDetail(CInt(Fix(GetCurrentColumnValue("CategoryID"))))
End Sub
Private Sub lbShowHide_PreviewClick(ByVal sender As Object, ByVal e _
As PreviewMouseEventArgs) Handles lbShowHide.PreviewClick
' Obtain the category's ID stored in the label's Tag property.
Dim index As Integer = CInt(Fix(e.Brick.Value))
' Determine whether the current category's details are shown.
Dim showDetail As Boolean = ShouldShowDetail(index)
' Toggle the visibility of the category's details.
If showDetail Then
expandedValues.Remove(index)
Else
expandedValues.Add(index)
End If
' Re-create a document to apply the changes.
CreateDocument()
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 lbShowHide_PreviewMouseMove(ByVal sender As Object, ByVal e _
As PreviewMouseEventArgs) Handles lbShowHide.PreviewMouseMove
Cursor.Current = Cursors.Hand
End Sub
鉆取報表就完成了。運行打印預覽表單,并查看結果。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:外文翻譯