Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Trouble with DataGridView - Exception: Object reference not set to an instance of an object.
 

Trouble with DataGridView - Exception: Object reference not set to an instance of an object.

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.DataGridView.CancelEdit(Boolean endEdit)
at System.Windows.Forms.DataGridView.ProcessEscapeKey(Keys keyData)
at System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
at System.Windows.Forms.DataGridView.ProcessKeyPreview(Message& m)
at System.Windows.Forms.Control.ProcessKeyPreview(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 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.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at topgear.FRM_12_37_1.dgvList_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) in D:\WinCVS\MCON\3.Source\vbnet\tkn-topgear\topgear\Forms\FRM_12_37_1.vb:line 222
at System.Windows.Forms.DataGridView.OnCellDoubleClick(DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnDoubleClick(EventArgs 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.DataGridView.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.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.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at topgear.FRM_MenuBase.Button1_Click(Object sender, EventArgs e) in D:\WinCVS\MCON\3.Source\vbnet\tkn-topgear\topgear\Forms\FRM_MenuBase.vb:line 123
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.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(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at topgear.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

=========================================================================================

That is Exception detail . I do not know what does it come from.
DGV datasource is BindingSource, using TableAdapter and DataSet (Tool wizard )
After loading data to DGV , editing data and pressing ESC , until DGV has nothing. I enter an radom value (just one column and any column) and then press ESC immediately , this exception will appear.
Can anyone help to tell me why ????
Thank you

Regards


Jerry_lth  Friday, November 16, 2007 4:00 AM

Hi Jerry_lth,

As far as I know, this error occurs when you try to set values for an object that is not initialized. I am not sure why this error occurs, but as you have said The DataGridView has nothing, I guess that you may forget to initialize some objects or there is something wrong with your dataset. Try to create a new dataset to see if this problem still happens.

Let me know if this helps. If not, could you please show some code?

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, November 22, 2007 7:49 AM

And what if I have over a million objects. Is there any way to know which object isn't responding

from an Exception ?

This would be a very interesting thing to add to Exception handling. The way to know WHICH object isn't referenced.

since .NET did catch an exception it should certainly knows which object it is

so must have a property somewhere that tell us which object it is no ?

This can also be a good question for MS !

Marc Roussel  Wednesday, December 12, 2007 3:27 PM

This issue is fixed in .net Fwk 2.0 SP1.

iamshail  Wednesday, January 30, 2008 7:39 PM

You can use google to search for other answers

Custom Search

More Threads

• Install TV Server into SQL Named Instance?
• Windows Update
• Improve mutations, please!
• System.CodeDom.Compiler.GeneratedCodeAttribute error
• Online/Offline Quirk
• DataGridView not raising CellPainting event
• Has Microsoft officially killed terrarium??
• Multi-part question in regards to functionality
• TaskVision - Source code installation help needed
• Treeview with contextMenustrip control