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

Issue with custom sorting

3 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George Saveliev
Top achievements
Rank 1
George Saveliev asked on 10 Aug 2010, 06:05 PM
Hello!

I have a problem with custom sorting in the latest WinForms RadGridView (2010.2.10.806). It worked well with version 2009.3.9.1203. I use Visual Studio 2008 with .NET 3.5. 

The code snippet is very simple:

01.foreach (GridViewDataColumn column in grid.Columns)
02.    column.CustomDataOperation = CustomDataOperation.Sorting;
03....
04.  
05.void grid_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
06.{
07.    MyItem item1 = grid.Rows[e.RowIndex1].DataBoundItem as MyItem;
08.    MyItem item2 = grid.Rows[e.RowIndex2].DataBoundItem as MyItem;
09.    ...
10.}

When the grid column header is clicked, the System.StackOverflowException occurs in grid_CustomSorting at the point where e.RowIndex1 or e.RowIndex2 is accessed. Moreover, it occurs even if we have 

1.void grid_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
2.{
3.    int ind1 = e.RowIndex1;
4.}

The second problem is that e.RowIndex1 can be negative even when the e.CellValue1 contains a good value.

So, how should I sort the grid by underlying data using my custom logic?

Thank you.

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 13 Aug 2010, 03:09 PM
Hello George Saveliev,

The issue with the custom sorting data operation and the RowIndex properties in event args is already known. It will be addressed in our Q2 2010 SP2 release, scheduled for the first half of September.

Currently, you can use reflected rowInfo objects:

void radGridView1_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
{
    FieldInfo fieldInfo = e.GetType().GetField("rowInfo1", BindingFlags.NonPublic | BindingFlags.Instance);
    if (fieldInfo != null)
    {
        GridViewRowInfo row1 = fieldInfo.GetValue(e) as GridViewDataRowInfo;
 
        fieldInfo = e.GetType().GetField("rowInfo2", BindingFlags.NonPublic | BindingFlags.Instance);
        GridViewRowInfo row2 = fieldInfo.GetValue(e) as GridViewDataRowInfo;
 
        MyItem item1 = row1.DataBoundItem as MyItem;
        MyItem item2 = row2.DataBoundItem as MyItem;
    }
}

Please excuse us for the caused inconvenience. I hope you find the above workaround helpful. Let me know if I can assist you further.

Sincerely yours,
Julian Benkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
George Saveliev
Top achievements
Rank 1
answered on 13 Aug 2010, 06:42 PM
Thank you for the workaround! It works for me.

JFYI: If the grid is grouped by some column and this column has CustomDataOperation = CustomDataOperation.Sorting, the CustomSorting() handler is called with e.Column = <that grouping column> regardless which column header was clicked.
0
Julian Benkov
Telerik team
answered on 18 Aug 2010, 06:27 PM
Hello George Saveliev,

I am glad to hear that everything works now. Thank you for your comments and the reported issue. Your Telerik points have been updated.

Greetings,
Julian Benkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
George Saveliev
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
George Saveliev
Top achievements
Rank 1
Share this question
or