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

RadGridView Sort Exception

10 Answers 222 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 05 Nov 2012, 07:10 PM
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!

10 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Nov 2012, 10:35 AM
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
0
Julian Benkov
Telerik team
answered on 07 Nov 2012, 01:43 PM
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.
0
Oliver
Top achievements
Rank 1
answered on 07 Nov 2012, 06:35 PM
Here is the code to set the SortDescriptor.

SortDescriptor descriptor = new SortDescriptor();
descriptor.PropertyName = "Show";
descriptor.Direction = ListSortDirection.Descending;
employeesGridView.MasterTemplate.SortDescriptors.Add(descriptor);
0
Emanuel Varga
Top achievements
Rank 1
answered on 08 Nov 2012, 07:13 AM
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
0
Oliver
Top achievements
Rank 1
answered on 08 Nov 2012, 06:10 PM
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.
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 12 Nov 2012, 11:22 AM
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
0
Julian Benkov
Telerik team
answered on 12 Nov 2012, 02:40 PM
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.
0
Oliver
Top achievements
Rank 1
answered on 12 Nov 2012, 06:18 PM
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!
0
Mark
Top achievements
Rank 1
answered on 28 May 2013, 12:44 PM
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.



0
Anton
Telerik team
answered on 31 May 2013, 11:50 AM
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?
Tags
GridView
Asked by
Oliver
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Julian Benkov
Telerik team
Oliver
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Anton
Telerik team
Share this question
or