Discussion:
DataGridView System.IndexOutOfRangeException
(too old to reply)
Tom
2009-07-28 22:22:01 UTC
Permalink
I have a DataGridView bound to an ObservableCollection. The Grid initializes
and fills. As soon as I click anywhere in the grid I get this exception. I
think I have had this one before but don't I can't figure out what the
problem is this time.


Index -1 does not have a value.
System.IndexOutOfRangeException
System.Windows.Forms

Thanks
Tom

The call stack

at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow,
Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti,
Boolean isShiftDown, Boolean isControlDown)
at
System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(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.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)
Chris Madsen
2009-07-29 01:11:33 UTC
Permalink
What happens in the click event for the datagridview?

Chris
Post by Tom
I have a DataGridView bound to an ObservableCollection. The Grid initializes
and fills. As soon as I click anywhere in the grid I get this exception. I
think I have had this one before but don't I can't figure out what the
problem is this time.
Index -1 does not have a value.
System.IndexOutOfRangeException
System.Windows.Forms
Thanks
Tom
The call stack
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs
e)
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow,
Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti,
Boolean isShiftDown, Boolean isControlDown)
at
System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(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.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)
Tom
2009-07-29 01:30:01 UTC
Permalink
I did not have one. I added one and it was never executed.

I did get A CurrentCellChanged event twice. The current cell went from 00 to
null.
Then a MouseDown event followed by a RowEnter event.

I never got a Click event.

Tom
Post by Chris Madsen
What happens in the click event for the datagridview?
Chris
Post by Tom
I have a DataGridView bound to an ObservableCollection. The Grid initializes
and fills. As soon as I click anywhere in the grid I get this exception. I
think I have had this one before but don't I can't figure out what the
problem is this time.
Index -1 does not have a value.
System.IndexOutOfRangeException
System.Windows.Forms
Thanks
Tom
The call stack
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs
e)
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow,
Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti,
Boolean isShiftDown, Boolean isControlDown)
at
System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(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.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)
miked
2009-09-18 19:42:01 UTC
Permalink
I was getting something similar, although I wasn't using an
ObservableCollection, but rather a List. I was attempting to rebound the
datasource to refresh the display, and ran in to the same exception (thrown
with an identical callstack).

I got around this by binding my collection to a BindingSource, and then
binging the BindingSource object to the DataGridView. Then, whenever I
needed to refresh the collection, it was a matter of calling ResetBindings on
my BindingSource object.

Hope it helps.
Post by Tom
I did not have one. I added one and it was never executed.
I did get A CurrentCellChanged event twice. The current cell went from 00 to
null.
Then a MouseDown event followed by a RowEnter event.
I never got a Click event.
Tom
Post by Chris Madsen
What happens in the click event for the datagridview?
Chris
Post by Tom
I have a DataGridView bound to an ObservableCollection. The Grid initializes
and fills. As soon as I click anywhere in the grid I get this exception. I
think I have had this one before but don't I can't figure out what the
problem is this time.
Index -1 does not have a value.
System.IndexOutOfRangeException
System.Windows.Forms
Thanks
Tom
The call stack
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs
e)
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow,
Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti,
Boolean isShiftDown, Boolean isControlDown)
at
System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(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.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)
KAN_T_
2009-12-09 07:34:01 UTC
Permalink
try "SuspendBinding Method" and "ResumeBinding"

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingmanagerbase.suspendbinding(VS.71).aspx
Post by miked
I was getting something similar, although I wasn't using an
ObservableCollection, but rather a List. I was attempting to rebound the
datasource to refresh the display, and ran in to the same exception (thrown
with an identical callstack).
I got around this by binding my collection to a BindingSource, and then
binging the BindingSource object to the DataGridView. Then, whenever I
needed to refresh the collection, it was a matter of calling ResetBindings on
my BindingSource object.
Hope it helps.
Post by Tom
I did not have one. I added one and it was never executed.
I did get A CurrentCellChanged event twice. The current cell went from 00 to
null.
Then a MouseDown event followed by a RowEnter event.
I never got a Click event.
Tom
Post by Chris Madsen
What happens in the click event for the datagridview?
Chris
Post by Tom
I have a DataGridView bound to an ObservableCollection. The Grid initializes
and fills. As soon as I click anywhere in the grid I get this exception. I
think I have had this one before but don't I can't figure out what the
problem is this time.
Index -1 does not have a value.
System.IndexOutOfRangeException
System.Windows.Forms
Thanks
Tom
The call stack
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs
e)
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow,
Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti,
Boolean isShiftDown, Boolean isControlDown)
at
System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs
e)
at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseDown(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.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)
KAN_T_
2009-12-09 07:37:02 UTC
Permalink
try "SuspendBinding Method" and "ResumeBinding"
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingmanagerbase.suspendbinding(VS.71).aspx
Loading...