原創|使用教程|編輯:我只采一朵|2014-01-17 09:34:28.000|閱讀 2355 次
概述:本文講解如何在DashboardViewer連接到數據庫之前自定義連接設置。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
上一講跟大家介紹了如何在 DevExpress Dashboard 中繪制Ribbon UI。本文將為你展示如何在DashboardViewer連接到數據庫之前使用DashboardViewer.ConfigureDataConnection事件自定義連接設置。
這里,儀表盤的XML定義包含一個連接到Microsoft Access數據庫的路徑。如果想讓數據庫文件中的數據可視,則必須提供連接參數,尤其是用戶名和密碼。DashboardViewer.ConfigureDataConnection事件的目的也在于此,它的 Access97ConnectionParameters.UserName 和 FileConnectionParametersBase.Password參數分別用于設置用戶名和密碼。
請參考以下代碼:
using System.Windows.Forms; using DevExpress.DataAccess.ConnectionParameters; namespace Dashboard_ConfigureDataConnection { public partial class Form1 : Form { public Form1() { InitializeComponent(); // Loads a dashboard from an XML file. dashboardViewer1.LoadDashboard(@"..\..\Data\nwindDashboard.xml"); } // Handles the ConfigureDataConnection event. private void dashboardViewer1_ConfigureDataConnection(object sender, DevExpress.DataAccess.ConfigureDataConnectionEventArgs e) { // Checks the name of the connection for which the event has been raised. if (e.ConnectionName == "nwindConnection") { // Gets the connection parameters used to establish a connection to the database. Access97ConnectionParameters parameters = (Access97ConnectionParameters)e.ConnectionParameters; // Specifies the user name used to access the database file. parameters.UserName = "Admin"; // Specifies the password used to access the database file. parameters.Password = "password"; } } } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件