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

Stack Overflow while sorting a grid

21 Answers 765 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 23 Jan 2012, 05:12 PM
I have a few virtual grids that have a somewhere between a few hundred and several thousand rows in them.

No matter what I try I am getting a stackoverflow error on the CellValueNeeded event anytime I try to sort any of my grids.

Not sure what to do here.

David

21 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 26 Jan 2012, 10:07 AM
Hello David,

I tested the described scenario using the virtual mode in RadGridView. However, I was not able to observe issues. Please, could you prepare a small project which reproduces the issue. This will allow us to investigate it in detail and provide you with further assistance. Thank you in advance.

I am looking forward to your reply.

All the best,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
lesley
Top achievements
Rank 1
answered on 18 May 2012, 12:32 PM
I have just tried similar code to David and I am also getting a Stack Overflow Exception in the CellValueNeeded Event after sorting.

I can reproduce the error with the following code.
Public Class Form1
    Private CellValueNeededCount As Integer = 0
    Private CellValue As Integer = -1
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        With RadGridView1
            .VirtualMode = True
            .Columns.Add("C1")
            .Columns.Add("C2")
            .Columns.Add("C3")
            .AllowAddNewRow = False
            .AllowDeleteRow = False
            .AllowEditRow = False
            .ShowGroupPanel = False
            .EnableFiltering = False
            .EnableGrouping = False
            .RowCount = 1000
        End With
    End Sub
 
    Private Sub RadGridView1_CellValueNeeded(sender As Object, e As Telerik.WinControls.UI.GridViewCellValueEventArgs) Handles RadGridView1.CellValueNeeded
        CellValueNeededCount += 1 ' with 10 rows visible =  30 for unsorted,18000+ for sorted
        Me.Text = CellValueNeededCount
 
        '**************************************************************************************************
        'Swapping the following lines will cause a stack overflow exception when sort
        e.Value = CellValue
        'e.Value = GetValueFromDataCache(e.RowIndex, e.ColumnIndex) 'e.RowIndex seems to be undefined when sorted
        '**************************************************************************************************
    End Sub
 
    Private Function GetValueFromDataCache(RowIndex As Integer, ColumnIndex As Integer) As Integer
        Return RowIndex + ColumnIndex + CellValue
    End Function
    Private Sub RadGridView1_SortChanged(sender As Object, e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles RadGridView1.SortChanged
        'SortDataCache(BuildOrderByText)
        RadGridView1.TableElement.Update(Telerik.WinControls.UI.GridUINotifyAction.DataChanged)
    End Sub
 
    Private Sub RadGridView1_SortChanging(sender As Object, e As Telerik.WinControls.UI.GridViewCollectionChangingEventArgs) Handles RadGridView1.SortChanging
        CellValueNeededCount = 0 'reset the count
        CellValue = CInt(Rnd(1) * 1000) 'new number to display
    End Sub
End Class

0
Julian Benkov
Telerik team
answered on 23 May 2012, 11:07 AM
Hi Lesley,

Indeed, RadGridView does not support filtering, sorting, and grouping in Virtual Mode. Only the UI and descriptor collections are updated. We found some issues when the RowIndex and ColumnIndex arguments are used in sorting operation. I logged the issues in our Public Issue Tracking System. Here you can find the PITS entry: Public URL. The fix will be available in one of the next releases.

Thank you for the report. Your Telerik points have been updated.

Regards,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Hannah
Top achievements
Rank 2
answered on 22 Oct 2013, 05:54 PM
I am currently experiencing this exact issue.  During my CellValueNeeded event that is fired immediately after typing in a single letter into a filter, the GridViewCellValueEventArgs seems to trigger a Stack Overflow exception.

Same is true for grouping.

Can you confirm that this was indeed fixed in the latest release?  I'm currently using v.2013.2.724.40

Thanks,

Wayne
0
George
Telerik team
answered on 25 Oct 2013, 03:26 PM
Hi Wayne,

Thank you for writing.

The issue in question has not yet been fixed. As said in this help article, the following operations are not support by RadGridView while in VirtualMode:
  • Grouping
  • Sorting
  • Filtering

As with VirtualMode you need to manage your DataSource manually the grid has no direct access to it, thus these operations are impossible with the current implementation of RadGridView. You can however perform the filtering and sorting operations directly on your DataSource collection.

Let me know if you have further questions.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Andrea
Top achievements
Rank 1
answered on 30 May 2014, 10:31 AM
Hello, I know GridView can't sort/group/filter data in virtual mode, but: it is possible to use the sort / filter events to actually sort/filter the local datasource cache without to have to write all the UI code that is already available to manage sort/filter using bound mode?

Is any VirtualModeUserWantsToSort(ColumnIndex, Ascending) , VirtualModeUserWantsToFilter(ColumnIndex, FilterDescriptor) event available to help virtual mode implementor to reuse the existing grid filter and sort descriptor user interface?

Or as an alternative: is possible to intercept column header click to sort data and display the sort arrow to the user and to put a customized filter row above each column that the user can use to insert search criteria (and a filter operator)?

0
George
Telerik team
answered on 04 Jun 2014, 01:07 PM
Hello Andrea,

Thank you for writing back.

Currently, we do not have such example. We are considering adding such article in future, should we add it, I will let you know in this thread.

You can intercept a header cell click by using the MouseClick event of RadGridView. You can also use the FilterChanging, SortChanging events to cancel the operations and still get the sort/filter expression which you can use to filter your data source. Note that after you have filtered your data you should set the RowCount property of RadGridView in order to refresh the data.

Let me know if you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Andrea
Top achievements
Rank 1
answered on 05 Jun 2014, 10:23 AM
Thank you for replying. I'll go for write a little UI that will associate to a grid to provide what I need, if that works i'll share.

Best regards.
0
George
Telerik team
answered on 10 Jun 2014, 08:13 AM
Hi Adnrea,

Feel free to share your solutions with the community or ask, should you need further assistance. You can use our Code Library section for sharing interesting solutions with the community.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
George
Telerik team
answered on 15 Jul 2014, 02:58 PM
Hi Andrea,

As I promised, I am getting back to you since we released an article which demonstrates how to use filtering, sorting and grouping with RadGridView and Virtual Mode. You can find the article on the following address: High Performance with RadGridView and Virtual Mode including Filtering, Sorting and Grouping.

Do not hesitate to let me know, should you have any questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Andrea
Top achievements
Rank 1
answered on 16 Jul 2014, 10:53 AM
Thank you that worked form me, with little adjustments (my datasource is a remote DB i do not need to load all rows locally)

I think in the same way i adapted to my orm can be done for who using relational databases / datatables / iqueryable.

It works fine.

Thank you very much, i did not have enough grid knowledge to be able to imagine this solution, i really appreciated.
0
lesley
Top achievements
Rank 1
answered on 18 Jul 2014, 04:04 AM
Thank you for the article and code George. Very awesome.
I can apply this to a few projects immediately.
0
George
Telerik team
answered on 21 Jul 2014, 08:46 AM
Hello,

I am glad that you were able to integrate this article into your projects.

Do not hesitate to write back, should you require further assistance, 

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Bob
Top achievements
Rank 1
answered on 15 Feb 2015, 07:57 PM
Hi George,

I downloaded your "High Performance with RadGridView and Virtual Mode including Filtering, Sorting and Grouping" sample and have been experimenting with it for a few days.  It's a very nice sample.  One thing I noticed is that if there is a group, sorting of the non-grouped columns no longer works.  Is this something that is even possible to implement?  If so, I could use a little direction.

Thanks,
Bob
0
Dimitar
Telerik team
answered on 18 Feb 2015, 12:51 PM
Hello Bob,

Thank you for writing.

This custom solution does not handle this particular case. However it is possible to implement such functionality. What needs to be done is to return proper value in the GetItemKey method in the VirtualGroupBuilder class. In addition you need to set the PagingBeforeGrouping property to false. You should create a dictionary that holds all items indexes as well (this just speeds up the process because using the IndexOf method is slow in this case).

I have attached an updated version of the project. To test this case just group by using the "id" column and then sort by "Name". 

I hope this will be useful. 

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Filippo
Top achievements
Rank 1
answered on 03 Sep 2015, 08:07 AM

Hello Dimitar,

  when I try to sort by Name, I get an exception:

System.InvalidOperationException non è stata gestita
  HResult=-2146233079
  Message=Sorting operation is not supported in VirtualMode.
  Source=Telerik.WinControls.GridView
  StackTrace:
       in Telerik.WinControls.UI.GridViewSortDescriptorCollection.InsertItem(Int32 index, SortDescriptor item)
       in System.Collections.ObjectModel.Collection`1.Add(T item)
       in Telerik.WinControls.UI.GridViewColumn.Sort(RadSortOrder sortOrder, Boolean multiSortMode)
       in Telerik.WinControls.UI.GridHeaderCellElement.Sort(RadSortOrder sortOrder)
       in Telerik.WinControls.UI.GridHeaderRowBehavior.OnMouseUp(MouseEventArgs e)
       in Telerik.WinControls.UI.BaseGridBehavior.OnMouseUp(MouseEventArgs e)
       in Telerik.WinControls.UI.RadGridView.OnMouseUp(MouseEventArgs e)
       in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       in System.Windows.Forms.Control.WndProc(Message& m)
       in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       in Telerik.WinControls.RadControl.WndProc(Message& m)
       in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       in System.Windows.Forms.Application.Run(Form mainForm)
       in VirtualRadGridViewSortingFiltering.Form.Program.Main() in C:\Users\Filippo\Documents\Visual Studio 2015\Projects\cb6cbbe6-2b56-4de1-83a1-24155c9e598a_virtualradgridview\VirtualRadGridViewSortingFiltering.Form\Program.cs:riga 19
       in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       in System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

  I don't understand if I missing something to  do...

  Thank you for your sample,

    Filippo

 

 

0
Andrea
Top achievements
Rank 1
answered on 03 Sep 2015, 08:20 AM

Hi FIlippo, this happens to the new version of the grid, they are aware of the problem and they are working on this, look at the following http://feedback.telerik.com/Project/154/Feedback/Details/166550-add-radgridview-add-means-for-a-virtual-grid-to-go-round-the-current-sort-fil , the eta is Q3 2015.

 

Best Regards

0
Filippo
Top achievements
Rank 1
answered on 03 Sep 2015, 09:42 AM

Thank you for this info,

  I'm trying to use EF 6.3 to access a SQL Server Database but I have a lot of performance issue if I have to call DBSet(T).Load just to get data sources for data-bounded RadGridView's templates.

  What I need is a Hierarchical GridView in virtual mode (also for childs...) and Sort, Group and Filter enabled functionalities.

  I'll try using Load-On-Demand but I don't know if "Add New Row" will work for children in hierarchy.

  Please consider this scenario for a future sample that will help a developer to solve performance issues quickly.

  Best of all will be if Telerik will implement this scenario inside RadGridView, for example setting DBSet(Of T) as datasource and loading data when needed.

  Best regards,

    Filippo.

0
Dimitar
Telerik team
answered on 07 Sep 2015, 01:43 PM
Hi Filippo,

Thank you for writing.

I have logged a feature request for this in our Feedback Portal. You can track the item for status changes and add your vote for it here.

When you are using load on demand hierarchy only the firs template is bound to the grid. If you want to add new rows, you should use the UserAddedRow and manually add the row to the data source. For example:
DataTable child = new DataTable();
void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
{
    child.Rows.Add(e.Row.Cells[0].Value, e.Row.Cells[1].Value);
    radGridView1.Templates[0].Refresh();
}

Your Telerik Points have been updated for this report.

Should you have any other questions do not hesitate to ask.


Regards,
Dimitar
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Filippo
Top achievements
Rank 1
answered on 11 Sep 2015, 10:50 AM

Hi Dimitar,

  I found another solution: I don't use load on demand hierarchy, instead I use databound hierarchy BUT... I eager load child entities in my DbContext in the ChildViewExpanding event.

  This trick lets me demand load entities using entity framework instead RadGridView.

  My solution is just more bit tricky due to other performance issues but this is the main idea.

  Now I have another problem because I think there is a bug in RadGridView. Please see my Bug Report ID:968829. I have a Data Exception that is impossible for me to understand.

   Best Regards,

  Filippo

0
Dimitar
Telerik team
answered on 15 Sep 2015, 09:49 AM
Hi David,

Since you have opened a support ticket, you can continue to discuss this case with the support staff there (where you can exchange projects) and once a resolution is reached, this forum thread can be updated.

Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
lesley
Top achievements
Rank 1
Hannah
Top achievements
Rank 2
George
Telerik team
Andrea
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Dimitar
Telerik team
Filippo
Top achievements
Rank 1
Share this question
or