Declined
Last Updated: 17 Nov 2017 11:17 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 06 Nov 2017 13:19
Category: PropertyGrid
Type: Bug Report
0
FIX. RaPropertyGrid - SortDescriptor.PropertyName is not respected when sorting programmatically
To reproduce:

        public RadForm1()
        {
            InitializeComponent();
             
            this.radPropertyGrid1.SelectedObject = new Item("zero", "uniqueId","alpha");

            this.radPropertyGrid1.EnableSorting = true;
            SortDescriptor sort = new SortDescriptor("Value", ListSortDirection.Ascending);
            this.radPropertyGrid1.SortDescriptors.Add(sort);
        }

        public class Item
        {
            public string Text { get; set; }
            
            public string Identifier { get; set; }

            public string Value { get; set; }

            public Item(string text, string identifier, string value)
            {
                this.Text = text;
                this.Identifier = identifier;
                this.Value = value;
            }
        }

Workaround#1: Set SortOrder to None

this.radPropertyGrid1.SortOrder = SortOrder.None;

Workaround#2: use a custom comparer:
            this.radPropertyGrid1.SortDescriptors.Add(sort);

            this.radPropertyGrid1.PropertyGridElement.PropertyTableElement.ListSource.CollectionView.Comparer = new MyComparer();

        public class MyComparer : IComparer<Telerik.WinControls.UI.PropertyGridItem>
        {
            int IComparer<Telerik.WinControls.UI.PropertyGridItem>.Compare(Telerik.WinControls.UI.PropertyGridItem x, Telerik.WinControls.UI.PropertyGridItem y)
            {
                if (x.Value != null && y.Value != null)
                {
                    return x.Value.ToString().CompareTo(y.Value.ToString());
                }
                return 0;
            }
        }
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
1 comment
ADMIN
Ralitsa
Posted on: 17 Nov 2017 07:12
Hello, 

After further investigation of the observed case, we consider that it is not an issue. The user should manually clear SortDescriptors` collection because there is default sort order Ascending for the properties in the object. Here is the code snippet how can be used: 

this.radPropertyGrid1.SelectedObject = new Item("alpha", "gamma", "beta");            
this.radPropertyGrid1.EnableSorting = true;
//clearing the default SortDescriptor
radPropertyGrid1.SortDescriptors.Clear();
SortDescriptor sort = new SortDescriptor("Value", ListSortDirection.Ascending);
this.radPropertyGrid1.SortDescriptors.Add(sort); 

Best regards, 
WinForms team