PropertyGrid for WPF | ComponentOne
In This Topic
    Sorting
    In This Topic

    By default properties and methods are listed alphabetically in the PropertyGrid control, similar to the Alphabetic view in the Visual Studio Properties window. However, you can customize the way members are listed in PropertyGrid by setting the PropertySort property. The PropertySort property can sort the properties in one of the following ways using the PropertySort enumeration:

    Set the C1PropertyGrid.PropertySort property to one of the above options to customize the way the property grid is sorted. The following images show how the PropertyGrid appears before sorting and after categorical custom sorting.

    PropertyGrid before sorting

    PropertyGrid with Categorized properties

    PropertyGrid after sorting

    PropertyGrid after sorting properties

     The following code demonstrates how the properties are sorted in PropertyGrid after applying categorical custom sorting:

    C#
    Copy Code
    public partial class Sorting : Window
    {
        public Sorting()
        {
            InitializeComponent();
    
            propertyGrid.SelectedObject = new Person()
            {
                UserName = "john_241",
                FirstName = "John",
                LastName = "Paul",
                DOB = new DateTime(1987, 2, 23),
                Email = "johnpaul241@gmail.com",
                Password = "john_@109$"
            };
    
            propertyGrid.PropertySort = PropertySort.CategorizedCustom;
        }
    }
    
    public class Person
    {
        //Order property for custom sorting
        //GroupName property categorizes the properties in PropertyGrid
    
        [Display(Order = 2, GroupName = "Personal")]
        public string FirstName { get; set; }
        [Display(Order = 3, GroupName = "Personal")]
        public string LastName { get; set; }
        [Display(Order = 1, GroupName = "Personal")]
        public string UserName { get; set; }
        [Display(Order = 5, GroupName = "Personal")]
        public DateTime DOB { get; set; }
        [Display(Order = 6, GroupName = "Login")]
        public string Password { get; set; }
        [System.ComponentModel.DataAnnotations.Display(Order = 4, GroupName = "Login")]
        public string Email { get; set; }
    }
    

    Back to Top