We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GridDataBoundGrid, sorting custom collection

Thread ID:





103009 Mar 22,2012 11:53 AM Mar 27,2012 09:08 AM Windows Forms 3
Tags: GridControl
Asked On March 22, 2012 11:53 AM

Does anybody have an example of custom collection sorting in GDBG?

I know that the grid is based on DataView sorting, but there were some examples of how to achieve this, unfortunately the links are broken, for example see


I cannot switch on GGC, because I use a GDBG descendant grid in my project and there are too much logic to move.

Thank you,

Replied On March 22, 2012 11:56 AM

Not necessary and example, any guidelines will be appreciated.

Replied On March 23, 2012 04:03 AM

Well, I've solved the problem by handling CellDoubleClick event where the e.RowIndex is equal to zero.

There I sort my collection and reassign the datasource.

private void selGridDataBoundGrid_CellDoubleClick(object sender, GridCellClickEventArgs e)
if (e.RowIndex == 0)
var sortCol = selGridDataBoundGrid.GridBoundColumns[e.ColIndex - 1].MappingName;
queue.SortColumn = sortCol;
queue.SortOrder = (queue.SortOrder == SortOrder.Ascending) ? SortOrder.Descending : SortOrder.Ascending;
selGridDataBoundGrid.DataSource = queue.GetSortedRequests();
e.Cancel = true;

I found the code for dynamyc Linq sorting on stackoverflow:

public static IOrderedQueryable OrderBy(this IQueryable source, string property)
return ApplyOrder(source, property, "OrderBy");
public static IOrderedQueryable OrderByDescending(this IQueryable source, string property)
return ApplyOrder(source, property, "OrderByDescending");
public static IOrderedQueryable ThenBy(this IOrderedQueryable source, string property)
return ApplyOrder(source, property, "ThenBy");
public static IOrderedQueryable ThenByDescending(this IOrderedQueryable source, string property)
return ApplyOrder(source, property, "ThenByDescending");
static IOrderedQueryable ApplyOrder(IQueryable source, string property, string methodName) {
string[] props = property.Split('.');
Type type = typeof(T);
ParameterExpression arg = Expression.Parameter(type, "x");
Expression expr = arg;
foreach(string prop in props) {
// use reflection (not ComponentModel) to mirror LINQ
PropertyInfo pi = type.GetProperty(prop);
expr = Expression.Property(expr, pi);
type = pi.PropertyType;
Type delegateType = typeof(Func<,>).MakeGenericType(typeof(T), type);
LambdaExpression lambda = Expression.Lambda(delegateType, expr, arg);

object result = typeof(Queryable).GetMethods().Single(
method => method.Name == methodName
&& method.IsGenericMethodDefinition
&& method.GetGenericArguments().Length == 2
&& method.GetParameters().Length == 2)
.MakeGenericMethod(typeof(T), type)
.Invoke(null, new object[] {source, lambda});
return (IOrderedQueryable)result;

By Marc Gravell


Mercy C [Syncfusion]
Replied On March 27, 2012 09:08 AM

Hi Vit,

Thanks for your interest in Syncfusion products.

We are glad to hear that you have resolved the custom collection sorting in DataBoundGrid with "CellDoubleClick" event.

Also, Please refer to the sample in the following link which makes use of "CellClick" and "PrepareViewStyleInfo" events to accomplish custom sorting.


Please let me know if you have any concerns.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.