I have recently upgraded our application from 14.1.6 to 15.1.7.
I have turned on the Conditional Formatting and was trying it out.
I changed the OptionsLayout Store FormatRules to true.
I then edited the grid to show some of the conditional formatting options and saved the xml to our server.
In my source code, when I refresh the query I save the current xml to a stream
System.IO.Stream compstream = new System.IO.MemoryStream();
xdoc.Save(compstream);
if (compstream.Position > 0)
{ compstream.Position = 0; }
Then after loading the data to the datasource I reload the xml
pivotSearchResults.BeginUpdate();
pivotSearchResults.RestoreLayoutFromStream(compstream);
pivotSearchResults.EndUpdate();
This is also performed immediately after I do an initial load of the XML from the server and execute the query, and this is when the error occurs.
When executing RestoreLayoutFromStream I get an ArgumentOutOfRangeException.
Note this only occurs for layouts that I saved with the StoreFormatRules option turned on and that I have configured conditional formatting for. We have a lot of previously stored layouts that were created in 14.1.6 and they load fine.
I have attached the xml that gives me the error.(this should be the same xml that is in the stream as immediately after I Save to the Stream , I performed a SaveLayoutToXml to create the file.
We have similar logic in our application for the xtragrid, and that works without a hitch.
As I cannot debug your methods, please let me know what in the xml is causing the error, and how I can work around this problem.
Hi Jeffrey,
I apologize for the delayed response. I have not managed to reproduce this issue on my side with a simple project. It is possible that this problem is specific to your data or current PivotGrid settings. Would you please modify my sample project to reproduce the issue?
We have researched the provided layout file and have not found any format rules in it. Does the problem appear when you restore this layout?
Our main application is fairly complex. I have tried removing all of the pivot table events, and setting the linked chart's datasource to null before executing this, but I still get the error. It doesn't appear to be a problem with the data or one specific layout.
I have attached a new xml file. The one I sent yesterday was saved directly from the control. In our application we load it from an xml we maintain in memory, they should be essentially the same but there may be some minor differences. That said, simply loading the layout into a pivotgrid won't reproduce the problem, however it may help you troubleshoot what is happening while looking at your source code.
Judging by the stack trace it is appears that when you are calling
DevExpress.XtraPivotGrid.Data.PivotFieldItemCollection.get_Item(Int32 index) internally the index you provide doesn't exist.
So simply making sure the index is valid before executing that method would fix the problem. As to why the index is not valid, I don't know enough about the internal workings of your code to say. Nor, do I know enough about your code to take a guess at what could be causing the problem in our specific implementation.
That said even if the problem can't be easily reproduced, some more robust loading logic in the pivotgrid would be a good improvement to the product overall.
The full stack trace is below:
場所 System.Collections.Generic.List`1.get_Item(Int32 index)
場所 DevExpress.XtraPivotGrid.Data.PivotFieldItemCollection.get_Item(Int32 index)
場所 DevExpress.XtraPivotGrid.Data.PivotGridData.GetFieldItem(PivotGridFieldBase field)
場所 DevExpress.XtraPivotGrid.Data.PivotGridViewInfoData.GetFieldItem(PivotGridFieldBase field)
場所 DevExpress.XtraPivotGrid.ViewInfo.PivotCellsViewInfoBase.CalculateCellsViewInfo()
場所 DevExpress.XtraPivotGrid.ViewInfo.PivotGridViewInfoBase.OnAfterCalculated()
場所 DevExpress.XtraPivotGrid.ViewInfo.PivotGridViewInfo.OnAfterCalculated()
場所 DevExpress.XtraPivotGrid.ViewInfo.BaseViewInfo.Calculate()
場所 DevExpress.XtraPivotGrid.ViewInfo.BaseViewInfo.EnsureIsCalculated()
場所 DevExpress.XtraPivotGrid.Data.PivotGridViewInfoData.get_ViewInfo()
場所 DevExpress.XtraPivotGrid.Customization.PivotCustomizationTreeBoxBase.get_PivotViewInfo()
場所 DevExpress.XtraPivotGrid.Customization.PivotCustomizationTreeBox.CalcItemHeight()
場所 DevExpress.XtraPivotGrid.Customization.CustomizationTreeBox.UpdateItemHeight()
場所 DevExpress.XtraPivotGrid.Customization.CustomizationTreeBox.Populate()
場所 DevExpress.XtraPivotGrid.Customization.CustomizationForm.Populate()
場所 DevExpress.XtraPivotGrid.Data.PivotGridViewInfoData.PopupateCustomizationFormFields()
場所 DevExpress.XtraPivotGrid.Data.PivotGridViewInfoData.EndUpdate()
場所 DevExpress.XtraPivotGrid.PivotGridControl.OnEndDeserializing(String restoredVersion)
場所 DevExpress.XtraPivotGrid.PivotGridControl.DevExpress.Utils.Serializing.IXtraSerializable.OnEndDeserializing(String restoredVersion)
場所 DevExpress.Utils.Serializing.Helpers.DeserializeHelper.CallEndDeserializing(Object obj, String layoutVersion)
場所 DevExpress.Utils.Serializing.Helpers.DeserializeHelper.RaiseEndDeserializing(Object obj, String restoredLayoutVersion)
場所 DevExpress.Utils.Serializing.Helpers.DeserializeHelper.DeserializeObject(Object obj, IXtraPropertyCollection store, XtraSerializationFlags parentFlags, OptionsLayoutBase options)
場所 DevExpress.Utils.Serializing.Helpers.DeserializeHelper.DeserializeObject(Object obj, IXtraPropertyCollection store, OptionsLayoutBase options)
場所 DevExpress.Utils.Serializing.XtraSerializer.DeserializeObject(Object obj, IXtraPropertyCollection store, OptionsLayoutBase options)
場所 DevExpress.Utils.Serializing.XtraSerializer.DeserializeObject(Object obj, Stream stream, String appName, OptionsLayoutBase options)
場所 DevExpress.Utils.Serializing.XtraSerializer.DeserializeObject(Object obj, Object path, String appName, OptionsLayoutBase options)
場所 DevExpress.XtraPivotGrid.PivotGridControl.RestoreLayoutCore(XtraSerializer serializer, Object path, OptionsLayoutBase options)
場所 DevExpress.XtraPivotGrid.PivotGridControl.RestoreLayoutFromStream(Stream stream, OptionsLayoutBase options)
場所 DevExpress.XtraPivotGrid.PivotGridControl.RestoreLayoutFromStream(Stream stream)
場所 VPSAnalyzer.CVPSAnalyzerBaseControl.LoadComponentXML(DXComponentType componenttype) 場所 c:\ViprosDebug\Pkg\Win\App\VPSAnalyzerDX_1_3_1\VPSAnalyzer\CVPSAnalyzerBaseControl.cs:行 11510
Ok, I was able to reproduce the problem in a more simple application, however you will need to provide your own data.
(it doesn't appear to be related to the data so as long as you have the same fields as I use in the previously attached xml you should be able to reproduce it).
To reproduce the problem,
* if you press the "LoadXML" button the problem does not occur, nor does the problem occur if you pres the LoadXML immediately before pressing "Save to Stream and Restore"
It appears to be related to the customization form. I was not able to reproduce the problem until I added the customization form to my sample.
Also note this problem did not occur in the past, also it only seems to occur after I have saved the xml in v15, but only if I have added conditional formatting. To test this I tried opening a layout created in v14, saved it again in v15 without making any changes, and when I reopen it, it works fine. The error only occurs after I add conditional formatting to the pivot.
If I load the component directly from the xml file, the error does not occur, the error only occurs if I load the xml file to a stream, and then load the pivotgrid from the stream.
Hi Jeffrey,
I have not managed to reproduce the problem with your project and a test data table. Attached is your modified sample project that operates without exceptions on my side.
As an immediate recommendation, remove BeginUpdate / EndUpdate methods from the btnSaveStream_Click method and let me know whether or not this helps.
I think with all the debugging I might not have sent the correct xml file. To avoid that problem I added the xml file that causes the issue to the project, and added your code to manually load the data. You should be able to reproduce the problem without changing anything this time.
Using the sample project, commenting out BeginUpdate/EndUpdate seemed to fix the problem. It was a bit more complicated for my application as the BeginUpdate is outside of the method where the error occurs but it appears to be working ok.
Regardless, I assume you probably want to make your code more robust by properly checking the bounds so I have attached my project, that combined with the stack trace I posted earlier should help you improve the code.
>>commenting out BeginUpdate/EndUpdate seemed to fix the problem.
I am happy to hear that you have resolved this issue.
>> I assume you probably want to make your code more robust by properly checking the bounds
The cause of this exception is that PivotGrid tries to apply settings to fields that are not yet created due to the locked updating. Checking collection bounds will not solve the problem. That's why we recommend you avoid using the BeginUpdate/EndUpdate methods in combination with the RestoreLayoutFrom~ methods.
Well, apparently you are doing something different now that is causing the error, because this code worked fine in 14.1.6. Also DevExpress.XtraPivotGrid.Data.PivotFieldItemCollection.get_Item(Int32 index) is where the error appears to occur because the "index" is greater than the collection size. That can be checked and handled, preferably to fix the problem but if nothing else just to provide better error handling. Also loading from an xml file doesn't seem to generate the error, so not sure what you are doing differently just because it is a stream. Regardless, I find it extremely hard to believe you cannot make the code more robust(as there are very few situations where this is true), whether or not you are interested in doing so is up to you.
Hi Jeffrey,
I have managed to reproduce this issue with the provided sample project and passed this ticket to our developers for further research. We will update this ticket once we have any results.