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:

Created:

Updated:

Platform:

Replies:

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

Hi,
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

http://staging.syncfusion.com/support/forums/grid-windows/28278/sorting-in-griddataboundgrid
or
http://staging.syncfusion.com/support/forums/grid-windows/28278/sorting-in-griddataboundgrid---again.


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,
Vit


Vitaly
Replied On March 22, 2012 11:56 AM

Not necessary and example, any guidelines will be appreciated.



Vitaly
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
http://stackoverflow.com/questions/41244/dynamic-linq-orderby

http://stackoverflow.com/questions/41244/dynamic-linq-orderby





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.

testgdbg66269254.ziphttp://www.syncfusion.com/downloads/Support/DirectTrac/92519/testgdbg62134213.zip

Please let me know if you have any concerns.

Regards,
Mercy.C


CONFIRMATION

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.

;