原創|使用教程|編輯:郝浩|2013-07-31 12:01:10.000|閱讀 278 次
概述:ActiveReports允許開發者在過濾器中使用參數,也允許開發者在運行時添加顯示數據到報表的。固可實現在報表運行過程中,最終用戶通過參數來改變報表輸出內容的需求。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
報表開發工具ActiveReports允許開發者在過濾器中使用參數,也允許開發者在運行時添加顯示數據到報表的。所以ActiveReports可以實現在報表運行過程中,最終用戶通過參數來改變報表輸出內容的需求。
最常見的需求場景是,經理使用報表查看器查看銷售報表時,需要分地區查看銷售業績,這時候就需要在查看器上添加一個下拉菜單作為過濾器來實現這一需求了。如下圖所示:
首先,需要在ActiveReports的Viewer窗體中添加一個Combobox,并將參數值填入其中。需要使用SQL查詢中的UNIQUE語句將數據集的值填入,示例代碼如下:
private void Form1_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\STDUser\My Documents\ComponentOne Samples\ActiveReports Developer 7\Data\NWIND.mdb;Persist Security Info=False"); System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand("select distinct country from customers", con); con.Open(); System.Data.OleDb.OleDbDataAdapter _da = new System.Data.OleDb.OleDbDataAdapter(command); _da.Fill(ds); comboBox1.ValueMember = "Country"; comboBox1.DataSource = ds.Tables[0]; con.Close(); }
在為下拉框添加了參數值后,需要將下拉框選擇的參數傳到報表中,使用組合框的SelectedIndexChanged事件:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { SectionReport1 rpt = new SectionReport1(); GrapeCity.ActiveReports.Data.OleDBDataSource _oDS = new GrapeCity.ActiveReports.Data.OleDBDataSource(); _oDS.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\STDUser\My Documents\ComponentOne Samples\ActiveReports Developer 7\Data\NWIND.mdb;Persist Security Info=False"; _oDS.SQL = "Select * from customers where country='" + this.comboBox1.SelectedValue + "'"; rpt.DataSource = _oDS; rpt.Run(); viewer1.LoadDocument(rpt); }
接下來就只需要執行ActiveReports的報表查看器就行了。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網