Sorting Groups and/or Properties

8 posts, 0 answers
  1. Devlin
    Devlin avatar
    7 posts
    Member since:
    Jul 2011

    Posted 29 Jul 2011 Link to this post

    Currently, groups are sorted alphabetically by their first constituent property definition (eg, if group 1 contains B, C, and D while group 2 contains A, E, and F, group 2 will appear first). Is there a way to control the sorting behavior of the groups-- for example, to sort by the groupname rather than by it's constituents? If not, is such a feature planned?
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 01 Aug 2011 Link to this post

    Hi Devlin,

    At this moment there is no easy way to achieve this functionality. You may try finding the ItemsControl that displays the groups and modify its ItemsSource. However, I wouldn't advise you to do so, because such a change may introduce new issues. We will consider adding this feature in some of our future releases.

    All the best,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Peter
    Peter avatar
    28 posts
    Member since:
    Oct 2006

    Posted 24 Feb 2012 Link to this post

    Hey there,

    this thread was posted a few months ago. Are there any changes in the current releases? I started using the PropertyGrid and I want to use the categorized view as default. Is there any way to accomplish this? In addition to that it would be nice if I could specify some kind of ordering (e.g. I want the some specific properties to always be on top). Some time ago I asked in the Silverlight forum for an enhanced support of .NET's DataAnnotations as they provide the interface for the requested behavior. Has there been some development in this area?

    Best regards,
    Peter Schmidt
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 24 Feb 2012 Link to this post

    Hi Peter,

    You can implement custom sorting logic by setting PropertyDefinition's OrderIndex property. Basically, it is designed for reordering of the PropertyGridField, but you can also easily manipulate groups' order by setting lower OrderIndex values to the PropertyDefinitions, which groups should be displayed first. As for the DataAnnotations support, with Q1 2012 we have introduced support for numerous property attributes: Display, Category, Description etc.

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Peter
    Peter avatar
    28 posts
    Member since:
    Oct 2006

    Posted 24 Feb 2012 Link to this post

    Hi Ivan,

    this is great! Thank you for this information. But one question is left: How can I programmatically group by category? As I have some DataObjects with many properties I would like to configure the PropertyGrid in a way that categorize is the default.

    Best regards,
    Peter Schmidt
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 27 Feb 2012 Link to this post

    Hello Peter,
     
    PropertyDefinitions in RadPropertyGrid are grouped by their GroupName property. It is either set when the PropertyDefinition is generated, or it is read from an attribute value. The supported attributes are the Category attribute and Display attribute's GroupName property. You may refer to the following demo that illustrates how it is working: demos > RadPropertyGrid > DataAnnotations support. As for the grouping at runtime, you can achieve this by stetting RadPropertyGrid's IsGrouped property.

    All the best,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  8. Peter
    Peter avatar
    28 posts
    Member since:
    Oct 2006

    Posted 27 Feb 2012 Link to this post

    Hi Ivan,

    thank you for your explanation. Infact, I configured the properties directly on the PropertyDefintion. But I think that DataAnnotations are a great way to configure the display. So e.g. the order of my properties will always be the same (and the user of my product will expect this), so it would be great if I could specify this on the data class itself.

    This is (except some annotations you have not yet implemented) the way your demo is working. But there is a problem with my solution. The data classes are generated via OpenAccess. So I can not set the DataAnnotations on the properties themself (would require to do this every time OpenAccess recreates my class files). I found out that with MetadataType I can specify a different class with the attributes. But it seems like your components do not react on this. I'm not that deep into Reflection but is it possible that there is some additional effort necessary to make this working:
    [MetadataType(typeof(pcUserMetaData))]
    public partial class pcUser
    {
    }
     
    public class pcUserMetaData
    {
        [Display(Order = 0, Name = "Username", GroupName="General")]
        public string UserName;
        [Display(Order = 5, Name = "Password", GroupName = "General")]
        public string Password;
    }


    By the way: Your tip with IsGrouped was great! Before that, I paged through all the properties of RadPropertyGrid but I never got the idea that IsGrouped might be the right one to choose. Thank you.

    Best regards,
    Peter Schmidt
  9. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 27 Feb 2012 Link to this post

    Hi Peter,

    As you are saying that the initial order will be constant, I believe that the easiest solution for your scenario would be to subscribe to RadPropertyGrid's AutogeneratingPropertyDefiniton event. The pending PropertyDefinition is exposed in event's arguments, so you can specify the OrderIndex and GroupName values there.

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
UI for WPF is Visual Studio 2017 Ready