User (Old forums)MemberJune 24, 2007 at 4:44 amPost count: 23064
i’m facing a problem and i wonder if it’s a bug, a grid’s limitation or if i’m doing something wrong.
Here’s the situation : when i click on the column header to sort the grid, an exception is thrown :
Extract of the stacktrace :
in System.Array.GetPivotValue(IComparer comparer, Array keys, Int32 left, Int32 right)
in Xceed.Wpf.DataGrid.DataGridControl.ApplyColumnSort(Column column, SortDirection sortDirection)
I have a simple test case to reproduce this behavior ( If you want, i can post the two files, but it’s probably easier for you to get them from pastebin.com ) :
If you click on the first column header, the sort happens as expected, but if you click on the second one, the exception is thrown.
With the same ItemsSource, the standard wpf listview have no problem.
Any ideas to how prevent this exception to be thrown ? ( of course i would like to keep the data under a hierachical form … )
Thanks for any advice.
Imported from legacy forums. Posted by Loic (had 877 views)User (Old forums)MemberJune 26, 2007 at 8:39 amPost count: 23064
We will look into this and follow-up in this thread.
Imported from legacy forums. Posted by Pascal (had 539 views)User (Old forums)MemberJune 27, 2007 at 11:00 amPost count: 23064
The exception occurs when there is a null Department.
I confirm that this is a bug, and we will fix it as soon as possible.
Thanks for bringing this to our attention!
Imported from legacy forums. Posted by Pascal (had 902 views)User (Old forums)MemberJune 28, 2007 at 8:28 amPost count: 23064
Thank you for your quick answer and thanks in advance for the future release.
Imported from legacy forums. Posted by Loic (had 369 views)Xceed SupportMemberJuly 13, 2007 at 3:08 pmPost count: 5658
I’ve been able to narrow the conditions based on your reproduction application posted on the C# PasteBin.
Unfortunately, it seems the reason why the ListView does not crash is because it’s not the same sort that is applied to both…
Effectively, when using the following code to sort:
string header = headerClicked.Column.Header as string;
Based on what is seen in the XAML file, clicking on any of the column would sort by “Name”… Moreover, the typical value of the Header property would not match the “Department.Name” display member path.
If the same “Department.Name” sort is applied to the ListView, this one will crash the same way…
There is currently no way in which we can fix the ListCollectionView’s way of sorting the data and therefore, we cannot “repair” this exception… But we are going to <b>try</b> adapting our DataGridCollectionView’s sorting to compensate this drawback… ( we are going to keep you posted on the feasibility of doing that)
Imported from legacy forums. Posted by Marcus [Xceed] (had 366 views)Xceed SupportMemberJuly 13, 2007 at 3:13 pmPost count: 5658
Moreover, there is a workaround that could be used to go “around” the exception…
Effectively, instead of binding the second column to “Department.Name”, you could bind it to “Department”. Then, you can and either create an implicit DataTemplate on the Department type or create a CellContentTemplate for the column; that displays the Name of the department.
Then, for the sorting, I have seen in the code of the sorting algorithm that it will use the IComparable interface, if availlable, on the objects to be sorted… therefore, you could implement some basic comparison logic (that turns back to comparing the strings of their Name).
Imported from legacy forums. Posted by Marcus [Xceed] (had 360 views)User (Old forums)MemberJuly 16, 2007 at 5:09 amPost count: 23064
thank you for this workaround. The problem is that if i have two columns : Department.LongName and Departement.ShortName, i will face a problem in my IComparable implementation : on which field do i compare my objects ? Maybe, i will just create new fields in my root objects ( like Department_Name ) when i need them.
Maybe you can add an overrideable method which is called when sorting is requested so that we can call the base.sort() method enclosed in a try/catch block : the sort will fail but the application will survive.
Anyway thank you for your investigation.
Imported from legacy forums. Posted by Loic (had 464 views)Xceed SupportMemberJuly 16, 2007 at 2:59 pmPost count: 5658
Unfortunately, we have no hook in the System classes that would allow us to prevent the crash (it is hidden deep). However, we are going to investigate the possibility to prevent this crash in our own collection view (DataGridCollectionView).
Imported from legacy forums. Posted by Marcus [Xceed] (had 5859 views)
- You must be logged in to reply to this topic.