Box のデータをDevExpress Data Grid にデータバインドする。

Box 用の CData ADO.NET プロバイダーをDevExpress Windows Forms とWeb コントロールとともに使用し、Box をチャートに入力します。

加藤龍彦
デジタルマーケティング

最終更新日:2022-01-31

この記事で実現できるBox 連携のシナリオ

こんにちは!ウェブ担当の加藤です。マーケ関連のデータ分析や整備もやっています。

Box 用の CData ADO.NET プロバイダーはサードパーティーコントロールで使うことのできる通常のADO.NET データベースアクセスコンポーネントを実装しています。データバインドするための通常のADO.NET プロセスに従うことで、UI コントロールから実データへの双方向アクセスを可能にします。 この記事では、CData を使ってDevExpress Windows Forms とウェブコントロールにデータバインドする方法を説明します。ここでは、最新のデータを表示するチャートにデータバインドします。

Box 接続プロパティの取得・設定方法

Box は、認証にOAuth スタンダードを使用します。Box への認証には、登録アプリのOAuthClientId、OAuthClientSecret、CallbackURL を取得して、接続プロパティに設定してください。詳細はヘルプドキュメントの「はじめに」を参照してください。

なお、Box Driver はBox のファイルの一覧表示やユーザー管理情報の取得用です。Box に保管されているExcel、CSV、JSON などのファイル内のデータを読み込みたい場合には、それぞれExcel DriverCSV DriverJSON Driver をご利用ください。

Windows Forms コントロール

下のコードでは、Box でDevExpress のチャートに追加する方法を説明します。BoxDataAdapter はチャートコントロールのSeries プロパティにバインドします。コントロールのDiagram プロパティはx 軸とy 軸をカラム名として定義します。

using (BoxConnection connection = new BoxConnection( "OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;")) { BoxDataAdapter dataAdapter = new BoxDataAdapter( "SELECT Name, Size FROM Files", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); DevExpress.XtraCharts.Series series = new DevExpress.XtraCharts.Series(); chartControl1.Series.Add(series); DataTable table = new DataTable(); series.ValueDataMembers.AddRange(new string[] { "Size" }); series.ArgumentScaleType = DevExpress.XtraCharts.ScaleType.Qualitative; series.ArgumentDataMember = "Name"; series.ValueScaleType = DevExpress.XtraCharts.ScaleType.Numerical; chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; ((DevExpress.XtraCharts.SideBySideBarSeriesView)series.View).ColorEach = true; } The complete code example and the resulting chart.

Web コントロール

下のコードではBox でDevExpress Web を操作するための設定方法を説明します。BoxDataAdapter はチャートのSeries プロパティにバインドします。Diagram プロパティはx 軸とy 軸をカラム名として定義します。 using DevExpress.XtraCharts; using (BoxConnection connection = new BoxConnection( "OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:33333;")) { BoxDataAdapter BoxDataAdapter1 = new BoxDataAdapter("SELECT Name, Size FROM Files", connection); DataTable table = new DataTable(); BoxDataAdapter1.Fill(table); DevExpress.XtraCharts.Series series = new Series("Series1", ViewType.Bar); WebChartControl1.Series.Add(series); DataTable table = new DataTable(); series.ValueDataMembers.AddRange(new string[] { "Size" }); series.ArgumentScaleType = ScaleType.Qualitative; series.ArgumentDataMember = "Name"; series.ValueScaleType = ScaleType.Numerical; ((DevExpress.XtraCharts.SideBySideBarSeriesView)series.View).ColorEach = true; } An ASP.NET application created with the ADO.NET Provider and the DevExpress Web Forms control.(Salesforce is shown.)

関連コンテンツ

トライアル・お問い合わせ

30日間無償トライアルで、CData のリアルタイムデータ連携をフルにお試しいただけます。記事や製品についてのご質問があればお気軽にお問い合わせください。