Bug Report B222636
Visible to All Users

Cannot set GridColumn.SortOrder

created 13 years ago

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

Show previous comments (3)
DevExpress Support Team 13 years ago

    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

      DevExpress Support Team 13 years ago

        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

        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.