Sorting SortedBindingList by child object property

Sorting SortedBindingList by child object property

Old forum URL: forums.lhotka.net/forums/t/11931.aspx


scjohnson posted on Wednesday, April 10, 2013

Hello,

I'm trying to sort a GridView by a property of a child object. I'm able to successfully set the DataField of a BoundField to the child column ("Application.Name"), but this doesn't work for sorting. How would I go about accessing this child property in the ApplySort method of a SortedBindingList?

 

Thanks,

Sam Johnson

JonnyBee replied on Wednesday, April 10, 2013

Hi,

SortedBindingList does not support sorting on a child property. Only properties on the actual object may be used for sorting.

So you could add an extra property to the list to project the child property or to use LINQ with projection but that requires more code in the UI and does not support editing of the list.

 

 

scjohnson replied on Thursday, April 11, 2013

Thank you! Using this, I was simply able to add the following property to the object and was able to sort:

public string ApplicationName
        {
            get { return this.Application.Name; }
        }

Copyright (c) Marimer LLC