如何绑定DevExpress PivotGridControl到数据库

 我来答
huanglenzhi
推荐于2016-11-28 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517192
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部

  本文通过一个具体的事例,为大家阐述如何绑定DevExpress的 PivotGridControl 到数据库。

  事例数据库如下:

  代码如下:

  C#

  

  using DevExpress.LookAndFeel;

  using DevExpress.XtraPivotGrid;

  using System.Data.OleDb;

  

  // Create a connection object.

  OleDbConnection connection =

  new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\DB\\NWIND.MDB");

  // Create a data adapter.

  OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM SalesPerson", connection);

  

  // Create and fill a dataset.

  DataSet sourceDataSet = new DataSet();

  adapter.Fill(sourceDataSet, "SalesPerson");

  

  // Assign the data source to the XtraPivotGrid control.

  pivotGridControl1.DataSource = sourceDataSet.Tables["SalesPerson"];

  

  // Create a row PivotGridControl field bound to the Country datasource field.

  PivotGridField fieldCountry = new PivotGridField("Country", PivotArea.RowArea);

  

  // Create a row PivotGridControl field bound to the Sales Person datasource field.

  PivotGridField fieldCustomer = new PivotGridField("Sales Person", PivotArea.RowArea);

  fieldCustomer.Caption = "Customer";

  

  // Create a column PivotGridControl field bound to the OrderDate datasource field.

  PivotGridField fieldYear = new PivotGridField("OrderDate", PivotArea.ColumnArea);

  fieldYear.Caption = "Year";

  // Group field values by years.

  fieldYear.GroupInterval = PivotGroupInterval.DateYear;

  

  // Create a column PivotGridControl field bound to the CategoryName datasource field.

  PivotGridField fieldCategoryName = new PivotGridField("CategoryName", PivotArea.ColumnArea);

  fieldCategoryName.Caption = "Product Category";

  

  // Create a filter PivotGridControl field bound to the ProductName datasource field.

  PivotGridField fieldProductName = new PivotGridField("ProductName", PivotArea.FilterArea);

  fieldProductName.Caption = "Product Name";

  

  // Create a data PivotGridControl field bound to the 'Extended Price' datasource field.

  PivotGridField fieldExtendedPrice = new PivotGridField("Extended Price", PivotArea.DataArea);

  fieldExtendedPrice.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric;

  // Specify the formatting setting to format summary values as integer currency amount.

  fieldExtendedPrice.CellFormat.FormatString = "c0";

  

  // Add the fields to the control's field collection.

  pivotGridControl1.Fields.AddRange(new PivotGridField[] {fieldCountry, fieldCustomer,

  fieldCategoryName, fieldProductName, fieldYear, fieldExtendedPrice});

  

  // Arrange the row fields within the Row Header Area.

  fieldCountry.AreaIndex = 0;

  fieldCustomer.AreaIndex = 1;

  

  // Arrange the column fields within the Column Header Area.

  fieldCategoryName.AreaIndex = 0;

  fieldYear.AreaIndex = 1;

  

  // Customize the control's look-and-feel via the Default LookAndFeel object.

  UserLookAndFeel.Default.UseWindowsXPTheme = false;

  UserLookAndFeel.Default.Style = LookAndFeelStyle.Skin;

  UserLookAndFeel.Default.SkinName = "Money Twins";

  

ZESTRON
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸... 点击进入详情页
本回答由ZESTRON提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式