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

Winforms GridView crashes if one assigns a new list of data to the data source after edit.

5 Answers 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erion
Top achievements
Rank 1
Erion asked on 23 Aug 2011, 08:02 PM
I have a grid view, which values can be edited by the user. I want to refresh the content of the grid, if the user changes the value of the cell. So say I have : 

1, 2, 3 as the initial state. If the user changes the value 2 to 5, i want the values in the grid to show , 1,5,6. ( this is a new list that's get assigned as data source to the gridview )

My understanding is that in order to refresh the grid. One has to create a new reference of the list and reasign it to the data source. 

When this is done in the CellValueChanged event, the gridview crashes, with the following error. 

How does one refresh the grid view after a value has changed ? 

- Thanks 

Steps to get the error : 

1. Create a GridView 
2. Assign it for data source a list of your favorite object. Strings or what not. 
3. Add a handler for the CellValueChanged. 
4. On the CellValueChanged handler, asign a new list of strings of your  to the grid's data source. 
5. Build start. Edit a cell, and hit enter. 

Error Message. 

   at Telerik.WinControls.UI.GridViewEditManager.EndEditCore(Boolean validate, Boolean cancel)
   at Telerik.WinControls.UI.GridViewEditManager.EndEdit()
   at Telerik.WinControls.UI.RadGridViewElement.EndEdit()
   at Telerik.WinControls.UI.GridRowBehavior.ProcessEnterKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.GridRowBehavior.ProcessKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridBehavior.ProcessKey(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridBehavior.ProcessKeyDown(KeyEventArgs keys)
   at Telerik.WinControls.UI.BaseGridEditor.OnKeyDown(KeyEventArgs keyEventArgs)
   at Telerik.WinControls.UI.GridSpinEditor.OnKeyDown(KeyEventArgs e)
   at Telerik.WinControls.UI.GridSpinEditor.spinElement_KeyDown(Object sender, KeyEventArgs e)
   at Telerik.WinControls.RadItem.OnKeyDown(KeyEventArgs e)
   at Telerik.WinControls.UI.RadSpinElement.OnKeyDown(KeyEventArgs e)
   at Telerik.WinControls.UI.RadSpinElement.textItem_KeyDown(Object sender, KeyEventArgs e)
   at Telerik.WinControls.RadItem.OnKeyDown(KeyEventArgs e)
   at Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyDown(Object sender, KeyEventArgs e)
   at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
   at System.Windows.Forms.TextBox.WndProc(Message& m)
   at Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Watson.ModelingTool.Main() in C:\Development\Watson\GL.Desktop\ModelingTool\ModelingTool.cs:line 45

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 24 Aug 2011, 11:54 AM
Hello Erion,

Thank you for your question.

Your scenario, rebinding RadGridView in the CellValueChanged event handler, is not valid in older versions of the control. However, it is implemented in the latest version of RadGridView - Q2 2011. Please update your project to this version and let us know if it behaves as expected. If you meet any difficulties regarding the upgrading process, we will be glad to assist you.

Best regards,
Alexander
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Erion
Top achievements
Rank 1
answered on 24 Aug 2011, 05:31 PM
Hi Alexander, 

So how should I handle this scenario ? Can I use other events, or I should just give up rebinding the grid to a new list on any event handler of the grid ? 

I have put the code on the EndEdit event and I still get the same error. 
- thanks 
I am using 2011.1.11.315 dll's.

- Erion
0
Erion
Top achievements
Rank 1
answered on 24 Aug 2011, 05:50 PM
Hi Alexander, 

I just updated the dll's to 2011.1.11.510, and I am still getting the crash. 

What do you mean by "Your scenario, rebinding RadGridView in the CellValueChanged event handler, is not valid in older versions of the control " ? 

Invalid as is not supported ? With the latest version from the website, I still have the option to listen to "CellValueChanged". 

Is there a way to refresh all the items in the grid based on change of value of one of the cells ? 
0
Erion
Top achievements
Rank 1
answered on 24 Aug 2011, 06:25 PM
Hi Alexander, 

My apologies for the second question. I didn't realize that I only have license for Q1 package. I am in the process of getting the Q2 dlls. 

I'll keep you posted. 

- Thanks . 
0
Erion
Top achievements
Rank 1
answered on 24 Aug 2011, 07:05 PM
Alexander, 

I just updated the dll's. 

It works :) 


Thank you 
Tags
GridView
Asked by
Erion
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Erion
Top achievements
Rank 1
Share this question
or