Hello!
I have a problem which I think was not present in an earlier version.
I have a grid like this:
<dxg:GridControl Name="gcProductPriceInfo" ItemsSource="{Binding Source={StaticResource cvsProductPriceInfo}}" AutoPopulateColumns="False">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="TPR_Product.PR_Num_ID" Header="No." Width="60" SortOrder="Ascending" />
<dxg:GridColumn FieldName="TPR_Product.PR_Shortname" Header="Short name" Width="150" />
</dxg:GridControl.Columns>
… etc. with cvsProductPriceInfo is a CollectionViewSource that is populated (by appliying a list to its .Source property) at runtime.
The problem is that the SortOrder="Ascending" of the first column does not work. THe sort order of that column is None after loading the window and I cannot change it to Ascending, even if I try in code, before I apply something to the cvsProductPriceInfo.Source. But as long as cvsProductPriceInfo.Source is null (and that will always be so in the beginning), setting the SortOrder property has no effect and getting it returns None. So it seems that there is no way to adjust the SortOrder in XAML.
Please please do not tell me that I need a Hot fix:(
Thanks
Karlo
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 Karlo,
Thank you for your report. We need additional time to research this problem. We will get back to you once we have any results. Your patience is appreciated.
Thanks,
Dmitry
Hi Karlo,
I have examined the code you provided and the only cause of the problem I could find is that the CollectionViewSource you are using as a grid's ItemSource does not support sorting (the CanSort property returns False). We already received similar reports, and the problem was connected the CollectionViewType at that time: the View property of the CollectionViewSource returned a BindingListCollectionView instance that does not support sorting, which leads to a problem. For instance, please look at the following thread, where a similar problem has been discussed:
Support for sorting an EntityCollection using CollectionViewSource
The problem you ran into has likely the same nature. So, I suggest that you modify the CollectionViewType property for your CollectionViewSource, as suggested in this thread and check if this makes a difference.
I hope this suggestion will help you address the problem. If this does not help, please provide us with a small sample project (along with a sample database) so that we can reproduce the issue locally and examine it in every detail.
Thanks,
Vito
Hi Vito,
I tried what you suggested and I changed my CollectionViewSource fom
<CollectionViewSource x:Key="cvsProductPriceInfo" />
into
<CollectionViewSource x:Key="cvsProductPriceInfo" CollectionViewType="{x:Type ListCollectionView}" />
This does not resolve the problem. Whether or not I make this change, it is possible to click the column header and change the sort order of that column (works). But the initial setting from the XAML is lost when the program starts up. So the initial setting SortOrder="Ascending" from the XAML is turned into "None" automatically and I cannot change a columns sort order prior to assigning my list of business objects to my cvsProductPriceInfo.Source in the code.
So the issue is not that sorting doesn't work in general (it works), but the definition of the sort order in XAML gets lost.
Thanks
Karlo
Hi Karlo,
Our developers have examined this behavior and come to the conclusion that it is by design. Settings adjusted in a collection view have higher priority than those of GridControl. This means that the collection view has its own sorting capabilities, which are triggered via SortDescriptions. GridControl uses the collection's SortDescriptions to apply sorting and avoid its own pre-defined settings. Therefore, when SortDescriptions are empty, sorting isn't applied regardless of GridControl sorting settings adjusted in XAML. GridControl is implemented this way to avoid possible conflicts when a single collection is assigned to several controls.
To solve the issue, apply sorting via SortDescriptions of the collection.
Thanks,
Ted
Thanks, Vito, for your answer.
The problem with declaring the sort column with
<CollectionViewSource.SortDescriptions>
is that, depending on the underlying list, I may receive exception like this:
'System.Windows.Data.BindingListCollectionView' view does not support sorting.
when I assign the list to the CollectionViewSource's Source property at runtime.
In a previous version of DevExpress then SortOrder properties of the column were respected and sorting just worked also in this case.
Karlo
Hi Karlo,
Yes, BindingListCollectionView doesn't support a sort description. However, we cannot foresee any combinations of list and collection types. If an ICollectionView implementation is used as an item source, GridControl doesn't allow predefined sorting. As I mentioned in my previous message, we have introduced this behavior to avoid conflicts when several controls use a single collection as an item source.
To address this situation, either use ObservableCollection as a CollectionView source or specify sorting at runtime after the InitializeComponent method call.
Thanks,
Ted