DevXpress 控件: 第一篇: 将 Master_Details 关系进行到底--XtraPivotGridControl控件
一. 控件說明: XtraPivotGridControl;數據控件
?
?
二. 控件特點:
1. 支持行, 列字段拖動, 對調
?? 支持行, 列字段的添加, 移除
?? 支持數據字段的添加, 移除, 對調
2. 支持以行, 列字段排序
??支持以過濾字段排序
3. 支持行, 列字段過濾??????????????????????????????????????????
4. 支持行, 列字段的歸類, 即形成父子層
橫向和豎向同時形成樹結構, 可收縮展開
?
三.測試數據: 1.數據庫: sqlserver2000; Norwind
???? 2.關聯表: Customers; Orders; Order_Details; Products;
???? 3.DevExpress 版本: V8.1
?
四. 運行截圖:
1.?????? 行字段: 客戶名稱;訂單號
列字段: 產品名稱
數據字段: 商品單價;購買數量
過濾字段: 客戶公司名稱;所簽合同名;訂購日期;截止日期;提貨日期
?
?2. 以客戶名稱進行過濾
?
3.?? 拖動行字段和列字段(此處演示對調)
產品名稱作為行, 客戶名稱作為列顯示
同時將過濾區的字段 訂購日期作加入列中
這樣重構樹: 客戶名稱à訂購日期
數據字段移除商品單價, 只保留購買數量
?
?
五. 程序代碼
1. 此處全部以 RunTime 進行設計
2. 綁定數據源:
(1):selectSql:
?this.sqlstr = "select a.*, b.*, c.*, d.* from Orders a inner join Order_Details b on a.OrderID=b.OrderID "
+ " inner join Customers c on a.CustomerID=c.CustomerID inner join Products d on b.ProductID=d.ProductID;";
(2): DataSource ; DataMember;
this.pivotGridControl1.DataSource = this.database.RunReturnDataSet(this.sqlstr);
this.pivotGridControl1.DataMember = this.database.dataSet.Tables[0].TableName;
3.????? 運行時添加字段
子逸制作--動態添加字段/// <summary>
/// 給消費鏈添加添加字段
/// </summary>
private void AddOrdersColumns()
{
//Customers表
PivotGridField customerID = new PivotGridField();
customerID.FieldName = "CustomerID";
customerID.Caption = "客戶名稱";
customerID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;
PivotGridField companyName = new PivotGridField();
companyName.FieldName = "CompanyName";
companyName.Caption = "客戶公司名稱";
companyName.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;
companyName.Width = 150;
PivotGridField contactTitle = new PivotGridField();
contactTitle.FieldName = "ContactTitle";
contactTitle.Caption = "所簽合同名";
contactTitle.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;
//Orders表
PivotGridField orderID = new PivotGridField();
orderID.FieldName = "OrderID";
orderID.Caption = "訂單號";
orderID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;
PivotGridField orderDate = new PivotGridField();
orderDate.FieldName = "OrderDate";
orderDate.Caption = "訂購日期";
orderDate.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;
PivotGridField requiredDate = new PivotGridField();
requiredDate.FieldName = "RequiredDate";
requiredDate.Caption = "截止日期";
requiredDate.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;
PivotGridField shippedDate = new PivotGridField();
shippedDate.FieldName = "ShippedDate";
shippedDate.Caption = "提貨日期";
shippedDate.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;
//OrderDetails
PivotGridField unitPrice = new PivotGridField();
unitPrice.FieldName = "UnitPrice";
unitPrice.Caption = "商品單價";
unitPrice.Area = DevExpress.XtraPivotGrid.PivotArea.DataArea;
PivotGridField Quantity = new PivotGridField();
Quantity.FieldName = "Quantity";
Quantity.Caption = "購買數量";
Quantity.Area = DevExpress.XtraPivotGrid.PivotArea.DataArea;
//Product表
PivotGridField productName = new PivotGridField();
productName.FieldName = "ProductName";
productName.Caption = "產品名稱";
productName.Area = DevExpress.XtraPivotGrid.PivotArea.ColumnArea;
//添加到控制中
this.pivotGridControl1.Fields.Add(customerID);
this.pivotGridControl1.Fields.Add(companyName);
this.pivotGridControl1.Fields.Add(contactTitle);
this.pivotGridControl1.Fields.Add(orderID);
this.pivotGridControl1.Fields.Add(orderDate);
this.pivotGridControl1.Fields.Add(requiredDate);
this.pivotGridControl1.Fields.Add(shippedDate);
this.pivotGridControl1.Fields.Add(unitPrice);
this.pivotGridControl1.Fields.Add(Quantity);
this.pivotGridControl1.Fields.Add(productName);
}
?
2.????? 運行時改變字段的顯示區域
?
?customerID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;
?
五. 屬性
1. 允許拖動
this.pivotGridControl1.OptionsCustomization.AllowDrag = true;
2. 允許排序
this.pivotGridControl1.OptionsCustomization.AllowSort = true;
3. 允許過濾
?this.pivotGridControl1.OptionsCustomization.AllowFilter = true;
?
六: 總結后記
1.????? 此控件較為靈活;對于 Master_Details 關系表處理的相當好;
2.????? 此控件數據區只能顯示數字類型字段, 類似于統計分析;
3.????? 后面會有更多的 DevExpress 控件介紹給大家
4.????? 這里只介紹控件的簡單使用;如需更復雜的技術支持或交流請與作者聯系;
QQ: 915571300?? 子逸
5.?????? 版權所有: 子逸(博客園);轉載請注明出處;
?
?
?
轉載于:https://www.cnblogs.com/ziyiFly/archive/2008/10/21/1315641.html
總結
以上是生活随笔為你收集整理的DevXpress 控件: 第一篇: 将 Master_Details 关系进行到底--XtraPivotGridControl控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “饮食断膻腥”上一句是什么
- 下一篇: 求一个好听的微信红包群名字