原創|使用教程|編輯:鄭恭琳|2019-09-18 11:39:15.933|閱讀 1561 次
概述:分組報告是數據分析所必需的。但是當有大量數據并且不需要全部顯示時,帶有分組的常規報告變得麻煩且多余。您希望為此類案例找到通用解決方案嗎?這里正好有一個。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
分組報告是數據分析所必需的。但是當有大量數據并且不需要全部顯示時,帶有分組的常規報告變得麻煩且多余。您希望為此類案例找到通用解決方案嗎?這里正好有一個。
帶有下拉列表的報告本質上是一個包含分組數據的報告,但能夠通過鼠標單擊隱藏或顯示組中的數據。它不僅非常方便,而且美觀。畢竟,報告成為一個交互式對象。當用戶可以參與信息顯示時,用戶會很高興。
考慮如何制作此類報告的示例。首先,與Master-Detail主從報表一樣(點擊這里查看如何制作Master-Detail主從報表>>),我們需要一個包含鏈接表的數據源。假設我們有兩個表:客戶和訂單。
一個客戶可以做很多訂單——一對多的關系。我們加上吧。單擊Actions按鈕,然后從下拉列表中選擇New Relation ...
父表是主表,然后選擇“customer”。子表分別是“orders”。在“customer”中有一個主鍵CustNo,在列表中選擇它。在“orders”中有一個外鍵CustNo,也選擇它。
結果,我們獲得了連接:
現在讓我們開始創建報告模板。添加一個頻段“group header”。在它上面我們將放置鏈接中的字段:“orders.customer.Company”、“orders.customer.Addr1”、“orders.customer.Phone”、“orders.customer.Contact”。
除了這些字段之外,我們還要為此頻段添加一個復選框控件。在CheckedSymbol屬性中,選擇Plus,然后選擇UncheckedSymbol - Minus。
添加“orders”表中的字段:OrderNo、SaleDate、PaymentMethod、AmountPaid到“Data”頻段。另外,為數據和字段標題添加標題區:
雙擊組標題“Headline”。選擇要分組的字段:
現在選擇我們之前添加的復選框。給它一個Hyperlink屬性:
選擇“Group Header”區域并為其創建BeforePrint事件處理程序:
private void GroupHeader1_BeforePrint(object sender, EventArgs e) { string groupName = (String)Report.GetColumnValue("orders.customer.Company"); // get the group name bool groupVisible = expandedGroups.Contains(groupName); // Check group visibility DataHeader1.Visible = groupVisible; Data1.Visible = groupVisible;// Set the visibility of data in accordance with the visibility of the group GroupFooter1.Visible = groupVisible;// Set the visibility of the basement of the group in accordance with the visibility of the group CheckBox1.Checked = !groupVisible;// Set the state of the flag depending on the visibility of the group }
還要向類添加擴展組列表:
private List expandedGroups = new List();
讓我們回到我們的復選框。為此,創建一個Click事件處理程序:
private void CheckBox1_Click(object sender, EventArgs e) { string groupName = (sender as CheckBoxObject).Hyperlink.Value; // We get the name of the group from the hyperlink if (expandedGroups.Contains(groupName)) // If the list of visible groups contains the selected group expandedGroups.Remove(groupName); // Then remove the selected from the list of visible groups. else expandedGroups.Add(groupName); // Otherwise add the group to the list of visible Report.Refresh(); // Update Report }
以預覽模式運行報告:
現在點擊任何加號:
當您單擊減號時會分組折疊。大神們都表示同意,這樣確實很方便。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn