Ticket T1287357
Visible to All Users

How do I support native sorting with my custom type?

created 11 days ago

Hi,

I have a gridcontrol, with an Ordinal column. I was helped in the past by enabling sorting on my columns to get it to sort – https://supportcenter.devexpress.com/ticket/details/t1242479

However, I have a different dialog that is generating columns based on a template (this is derived from a separate devexpress example). My type is Ordinal (referenced in the link above, a very simple type, which implements IComparer and IComprable).

When I enable AllowSorting, I get an error when I go to sort, directly on the Panel. Is there some type of configuration changes I can make to get sorting to work my record types, in this dynamically generated column set?

Clipboard-File-1.png

XAML
<DataTemplate x:Key="BindingColumnTemplate"> <!-- How to build a header column --> <dxg:GridColumn Width="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).Width, RelativeSource={RelativeSource Self}}" MinWidth="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).MinWidth, RelativeSource={RelativeSource Self}}" MaxWidth="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).MaxWidth, RelativeSource={RelativeSource Self}}" localBindings:BindingHelper.Path="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).FieldName, RelativeSource={RelativeSource Self}}" AllowSorting="True" Header="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).Header, RelativeSource={RelativeSource Self}}" HeaderToolTip="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).ToolTip, RelativeSource={RelativeSource Self}}" Visible="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).IsVisible, RelativeSource={RelativeSource Self}}" /> </DataTemplate>
C#
public static readonly DependencyProperty PathProperty = DependencyProperty.RegisterAttached( "Path", typeof(string), typeof(BindingHelper), new PropertyMetadata((d, e) => { if (!string.IsNullOrWhiteSpace(e.NewValue as string)) { ((GridColumn)d).Binding = new Binding((string)e.NewValue) { Mode = BindingMode.OneWay }; } })

Answers approved by DevExpress Support

created 10 days ago (modified 10 days ago)

Hello Greg,

Thank you for the detailed description.

At first glance, you can implement the IComparable interface for the underlying class instead of IComparable<T>:

C#
public record Ordinal : IComparable { public int Value { get; set; } public static Ordinal Empty = new Ordinal() { Value = -1 }; public int CompareTo(object other) { if (other is not Ordinal ordinal) { return 0; } return this.Value.CompareTo(ordinal.Value); } }

Please let me know if this helps.

Regards,
Alexander

    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.