DevXpress 控件: 第一篇: 将 Master_Details 关系进行到底--XtraPivotGridControl控件
一. 控件說明: XtraPivotGridControl;數(shù)據(jù)控件
?
?
二. 控件特點:
1. 支持行, 列字段拖動, 對調(diào)
?? 支持行, 列字段的添加, 移除
?? 支持?jǐn)?shù)據(jù)字段的添加, 移除, 對調(diào)
2. 支持以行, 列字段排序
??支持以過濾字段排序
3. 支持行, 列字段過濾??????????????????????????????????????????
4. 支持行, 列字段的歸類, 即形成父子層
橫向和豎向同時形成樹結(jié)構(gòu), 可收縮展開
?
三.測試數(shù)據(jù): 1.數(shù)據(jù)庫: sqlserver2000; Norwind
???? 2.關(guān)聯(lián)表: Customers; Orders; Order_Details; Products;
???? 3.DevExpress 版本: V8.1
?
四. 運行截圖:
1.?????? 行字段: 客戶名稱;訂單號
列字段: 產(chǎn)品名稱
數(shù)據(jù)字段: 商品單價;購買數(shù)量
過濾字段: 客戶公司名稱;所簽合同名;訂購日期;截止日期;提貨日期
?
?2. 以客戶名稱進(jìn)行過濾
?
3.?? 拖動行字段和列字段(此處演示對調(diào))
產(chǎn)品名稱作為行, 客戶名稱作為列顯示
同時將過濾區(qū)的字段 訂購日期作加入列中
這樣重構(gòu)樹: 客戶名稱à訂購日期
數(shù)據(jù)字段移除商品單價, 只保留購買數(shù)量
?
?
五. 程序代碼
1. 此處全部以 RunTime 進(jìn)行設(shè)計
2. 綁定數(shù)據(jù)源:
(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.????? 運行時添加字段
子逸制作--動態(tài)添加字段/// <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 = "購買數(shù)量";
Quantity.Area = DevExpress.XtraPivotGrid.PivotArea.DataArea;
//Product表
PivotGridField productName = new PivotGridField();
productName.FieldName = "ProductName";
productName.Caption = "產(chǎn)品名稱";
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.????? 運行時改變字段的顯示區(qū)域
?
?customerID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;
?
五. 屬性
1. 允許拖動
this.pivotGridControl1.OptionsCustomization.AllowDrag = true;
2. 允許排序
this.pivotGridControl1.OptionsCustomization.AllowSort = true;
3. 允許過濾
?this.pivotGridControl1.OptionsCustomization.AllowFilter = true;
?
六: 總結(jié)后記
1.????? 此控件較為靈活;對于 Master_Details 關(guān)系表處理的相當(dāng)好;
2.????? 此控件數(shù)據(jù)區(qū)只能顯示數(shù)字類型字段, 類似于統(tǒng)計分析;
3.????? 后面會有更多的 DevExpress 控件介紹給大家
4.????? 這里只介紹控件的簡單使用;如需更復(fù)雜的技術(shù)支持或交流請與作者聯(lián)系;
QQ: 915571300?? 子逸
5.?????? 版權(quán)所有: 子逸(博客園);轉(zhuǎn)載請注明出處;
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/ziyiFly/archive/2008/10/21/1315641.html
總結(jié)
以上是生活随笔為你收集整理的DevXpress 控件: 第一篇: 将 Master_Details 关系进行到底--XtraPivotGridControl控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “饮食断膻腥”上一句是什么
- 下一篇: 求一个好听的微信红包群名字