RadGridView Sort Exception

11 posts, 1 answers
  1. Oliver
    Oliver avatar
    17 posts
    Member since:
    Aug 2008

    Posted 05 Nov 2012 Link to this post

    I set up a SortDescriptor on my RadGridView using the example from http://www.telerik.com/help/winforms/gridview-sorting-setting-sorting-programmatically.html but I keep getting an exception thrown randomly:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.WinControls.UI.GridViewEditManager.InitializeEditor(IInputEditor activeEditor)
       at Telerik.WinControls.UI.GridViewEditManager.BeginEdit()
       at Telerik.WinControls.UI.GridRowBehavior.OnMouseUpLeft(MouseEventArgs e)
       at Telerik.WinControls.UI.GridRowBehavior.OnMouseUp(MouseEventArgs e)
       at Telerik.WinControls.UI.BaseGridBehavior.OnMouseUp(MouseEventArgs e)
       at Telerik.WinControls.UI.RadGridView.OnMouseUp(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at Telerik.WinControls.RadControl.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    The descriptor is being used on a boolean checkbox column.  Even though it throws the exception, the sort still executes.  Any help would be appreciated.  Thanks!
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 07 Nov 2012 Link to this post

    Hello Julia,

    How are you setting the sort descriptor on the column? 

    Could you please provide some sample code?

    Best Regards,
    Emanuel Varga
    Winforms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 07 Nov 2012 Link to this post

    Hello Julia,

    I have tested the described behavior but I was not able to replicate the exception on my end. If you continue to experience the issues, please send me a sample application with some part of your data so we can review the specific case and try to find the best solution it. 

    Thank you for your time and cooperation.

    Regards,
    Julian Benkov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  5. Oliver
    Oliver avatar
    17 posts
    Member since:
    Aug 2008

    Posted 07 Nov 2012 Link to this post

    Here is the code to set the SortDescriptor.

    SortDescriptor descriptor = new SortDescriptor();
    descriptor.PropertyName = "Show";
    descriptor.Direction = ListSortDirection.Descending;
    employeesGridView.MasterTemplate.SortDescriptors.Add(descriptor);
  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Nov 2012 Link to this post

    Hello again,

    I have to rephrase, the question was where in the code? On what event?

    because in the exception you posted we have
    at Telerik.WinControls.UI.GridViewEditManager.InitializeEditor(IInputEditor activeEditor)
     at Telerik.WinControls.UI.GridViewEditManager.BeginEdit()
    so, you are trying to sort when the editor is active.

    I believe this is the problem, try to perform the sort when the grid is not in edit mode.

    I hope this helps, If you have any other questions, please let me know.

    Best Regards,
    Emanuel Varga
    Winforms MVP
  7. Oliver
    Oliver avatar
    17 posts
    Member since:
    Aug 2008

    Posted 08 Nov 2012 Link to this post

    I set the SortDescriptor when I set all of the settings for the RadGridView in my program constructor.  I've also tried just calling RadGridView.Columns["myColumn"].Sort() in my RadGridView's ValueChanged event after calling .EndEdit() on it and that doesn't solve the problem.
  8. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 12 Nov 2012 Link to this post

    Hello again,

    Calling the Sort() in some grid event is not a good ideea, because there are some asynchronous things being done in the grid after that event, (cause of your exception).

    This is not related to your sort issue, please check on the column header if the sort indicator is present on your column after your grid initialization.

    If yes and the sort is not performed please try to create a small example to demonstrate your issue (even a screenshot and some explanation about the types you are trying to sort would be a very good start), otherwise there is not much i can do to help.

    Best Regards,
    Emanuel Varga
    WinForms MVP
  9. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 12 Nov 2012 Link to this post

    Hello Julia,

    If you continue experiencing issues after Emanuel’s suggestions please, open a support ticket where you can provide us with a sample project demonstrating the experienced behavior. This will allow us to investigate this case which is a necessary step in order to be able to address it.

    Thank you for your cooperation. I am looking forward to your response.

    All the best,
    Julian Benkov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  10. Oliver
    Oliver avatar
    17 posts
    Member since:
    Aug 2008

    Posted 12 Nov 2012 Link to this post

    I finally was able to implement a work-around...

    I noticed that the exception only occurred when I would click the boolean cell outside of the checkbox, and then click the checkbox to change the value.  My guess is that by clicking the cell it goes into edit mode and then when I clicked the checkbox initiating a sort, it was trying to sort while in edit mode.

    I set the column to read-only and programmed value changes to happen in the CellClick event handler and now it works perfectly.  Probably not the best solution, but it works fine for what I need it to do :/.

    Thank you Julian and Emanuel for all your help!
  11. Mark
    Mark avatar
    32 posts
    Member since:
    Jan 2012

    Posted 28 May 2013 Link to this post

    Hi

    I am experiencing exactly the same exception as this (the full stack trace is identical) but am struggling to characterize the problem. I am getting a consistent error in our main application but can't reproduce when trying to construct a sample project.

    My main setup is :

    I have a grid with various data items including text fields, editable text fields, checkboxes and buttons which is loaded with data.

    I am able to consistently get the exception when I re-order the data (by clicking on a column header) for a checkbox column under the following circumstances:

    The grid is loaded but has not been touched yet so that row one is auto highlighted. I then re-order the data by clicking the header row of one of the checkbox columns. The data is re-ordered, but importantly for the exception scenario, ROW ONE DOES NOT CHANGE,. i.e, before and after the re-order, row one contains the same data. Try to check the checkbox in row one, and get the exception detailed in this post. I can change the checkbox in a different column OK (one that was not sorted on)

    I'll see if I can re create the issue in a sample application and submit a ticket if I can, however in the meantime this is the scenario that fails, so hopefully may give some pointers to investigate whether there is problem.

    Many thanks,

    Mark.



  12. Anton
    Admin
    Anton avatar
    167 posts

    Posted 31 May 2013 Link to this post

    Hi Mark,

    Thank you for writing.

    The provided information is not enough for me to determine what causes this behavior on your side. Your case seems to be complex and we will not be able to find what is reason for the undesired behavior without debugging it. This is why I would like to kindly ask you to provide me a runnable project where the issue occurs. Once I am able to debug it, I will do my best to provide you with solution.

    You can attach the project in the ticket you have opened : "Exception clicking Checkbox after Sort".

    I am looking forward to your reply.

    Regards,
    Anton
    Telerik
    RadChart for WinForms is obsolete. Now what?
Back to Top
UI for WinForms is Visual Studio 2017 Ready