Dear Support,
I want to set to query by SQL to bind to the PivotGrid in Analysis. I have worked on AnalysisDataBindController to do something when the BindDataAction is executed as following:
Analysis analysis = (Analysis) View.CurrentObject;
ObjectSpace objectSpace = (ObjectSpace) this.ObjectSpace;
string sql = "SELECT P.PoNo, P.SoNo, CAST(P.PoDate as smalldatetime) as PoDate, P.VendorCode, ";
sql += @"P.VendorName, P.ShipToCode, P.ShipToName, ";
sql += @"SUM(D.UnitPrice * D.Quantity) as [Amount] FROM PO P ";
sql += @"LEFT OUTER JOIN PO_Detail D ON P.Oid = D.Po ";
sql += @"GROUP BY P.PoNo, P.SoNo, P.PoDate, P.VendorCode, P.VendorName, P.ShipToCode, P.ShipToName ";
sql += @"ORDER BY Amount DESC ";
SelectedData selectedData = objectSpace.Session.ExecuteQuery(sql);
XPDataView xpDataView = new XPDataView();
xpDataView.AddProperty("PoNo", typeof(String));
xpDataView.AddProperty("SoNo", typeof(String));
xpDataView.AddProperty("PoDate", typeof(DateTime));
xpDataView.AddProperty("VendorCode", typeof(String));
xpDataView.AddProperty("VendorName", typeof(String));
xpDataView.AddProperty("ShipToCode", typeof(String));
xpDataView.AddProperty("ShipToName", typeof(String));
xpDataView.AddProperty("Amount", typeof(Decimal));
xpDataView.LoadData(selectedData);
editor.Control.DataSource = new AnalysisDataSource(analysis, xpDataView);
editor.Control.PivotGrid.DataBind();
However, the PivotGrid can't display any data but only the column header. I tried to stop at debug before editor.Control.PivotGrid.DataBind() and sure the xpDataView have get the correct data from database. What wrong with my code? Please help.
Regards,
Gary
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hi Gary,
It seems that you are providing your data source at a wrong moment. Please handle the AnalysisEditorBase.DataSourceCreating event, assign your data source to the e.DataSource parameter, and set the e.Handled parameter to True.
public partial class MyAnalysisDataBindController : AnalysisDataBindController { protected override void OnActivated() { base.OnActivated(); this.analysisEditor.DataSourceCreating += new EventHandler<DataSourceCreatingEventArgs>(analysisEditor_DataSourceCreating); } protected override void OnDeactivated() { this.analysisEditor.DataSourceCreating -= new EventHandler<DataSourceCreatingEventArgs>(analysisEditor_DataSourceCreating); base.OnDeactivated(); } void analysisEditor_DataSourceCreating(object sender, DataSourceCreatingEventArgs e) { ObjectSpace objectSpace = (ObjectSpace)this.ObjectSpace; string sql = "..."; SelectedData selectedData = objectSpace.Session.ExecuteQuery(sql); XPDataView xpDataView = new XPDataView(); //... e.DataSource = xpDataView; e.Handled = true; } }
Thanks,
Michael.
Dear Michael,
Thank you for your prompt reply.
I followed your suggestion to create a new controller inherit from AnalysisDataBindController and place such data binding code into the registered DataSourceCreating event.
However, it runs with error "The data source is of an invalid type. It must be an IListSource, IEnumerable or IDataSource." after I clicked "Bind Analysis Data" button as attached print screen.
Anything I did wrongly?
Regards,
Gary
Hi Gary,
I am afraid I cannot diagnose this issue using a screenshot. Please provide us with the source code of your controller or better yet, with a small sample project reproducing the issue.
Thanks,
Michael.
Dear Michael,
Thank you for your reply. The problem was solved as I replace:
e.DataSource = new AnalysisDataSource(analysis, xpDataView);
To
e.DataSource = xpDataView;
Would you please explain why I can directly bind the data source to a XPDataView object as don't need to create a instance of AnalysisDataSource with parameter of the specific analysis object ?
Actually, I was following the document at http://documentation.devexpress.com/#Xaf/CustomDocument3025 to control the PivotGrid in Coding.
Regards,
Gary
Hi Gary,
You cannot assign the AnalysisDataSource class to the e.DataSource parameter because this class does not implement any of the required interfaces.
I cannot find any references to the AnalysisDataSource class in the documentation article you pointed to.
Thanks,
Michael.
Sorry Michael,
I pointed the wrong link at previous post.
The usage of AnalysisDataSource is actually found in http://documentation.devexpress.com/#xaf/CustomDocument3050 which demonstrates how to distribute the created analysis with saved configuration.
From my understanding on this post, it is necessary to bind the data source to an analysis object by AnalysisDataSource class. How your codes work as the PivotGrid could be directly bind to an XPDataView?
Your code is working fine now in my program now but I still just want to understand more in depth about the technical stuffs in analysis of XAF.
Thank you!
Gary
Hi Gary,
The AnalysisDataSource instance is required for IAnalysisControl, but the actual data source assigned to the pivot grid is AnalysisDataSource.DataSource - the one you pass in the AnalysisDataSource constructor.
Please let me know if you need any additional assistance.
Thanks,
Michael.
Dear Michael,
Thank you for your explanation. It is clear now.
Regards,
Gary
You are welcome, Gary.
Please let me know if I can help you further.
Thanks,
Michael.