This is a migrated thread and some comments may be shown as answers.

Sorting Groups and/or Properties

7 Answers 342 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Devlin
Top achievements
Rank 1
Devlin asked on 29 Jul 2011, 08:01 PM
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?

7 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 01 Aug 2011, 03:25 PM
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 >>
0
Peter
Top achievements
Rank 1
answered on 24 Feb 2012, 04:14 PM
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
0
Ivan Ivanov
Telerik team
answered on 24 Feb 2012, 04:28 PM
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 >>
0
Peter
Top achievements
Rank 1
answered on 24 Feb 2012, 05:39 PM
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
0
Ivan Ivanov
Telerik team
answered on 27 Feb 2012, 09:49 AM
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 >>
0
Peter
Top achievements
Rank 1
answered on 27 Feb 2012, 12:19 PM
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
0
Ivan Ivanov
Telerik team
answered on 27 Feb 2012, 01:01 PM
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 >>
Tags
PropertyGrid
Asked by
Devlin
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Peter
Top achievements
Rank 1
Share this question
or