Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataGridView Index -1 does not have a value

198 views
Skip to first unread message

AlexMich

unread,
Nov 9, 2006, 6:16:39 PM11/9/06
to
Hi,

I have a datagridview with a datasource set to an arraylist of custom
business objects. When I add a first element to my arraylist and rebind
the datasource of my datagridview to it, the new row is perfectly
displayed. But as soon as I try to click the new added row, BANG ! I
receive the following error :

Error: System.IndexOutOfRangeException: Index -1 does not have a value.
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.CurrencyManager.get_Current()
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.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 TestRemoting.ModuleMain.Main() in C:\Documents and
Settings\cenmichaudal\My Documents\Visual Studio
2005\Projects\NotShip-Server-side\TestRemoting\ModuleMain.vb:line 8

What is the most interesting thing in all this, is that I have a form
in which I do the exact same thing and I have no problem at all !!! I
have cross-checked all the properties of both datagridview and they are
all the same... What is GOING ON !!! PLEASE HELP ME ON THIS !!!

RobinS

unread,
Nov 9, 2006, 6:18:43 PM11/9/06
to
You could try using a Generic List instead.

Robin S.

"AlexMich" <alex_mi...@hotmail.com> wrote in message
news:1163114199.2...@i42g2000cwa.googlegroups.com...

AlexMich

unread,
Nov 10, 2006, 4:40:52 PM11/10/06
to
FINALLY FOUND IT !!!

So maybe it can help others.... 2 days of hard work that is what it
cost me...

Just in case you run into similar b...shit. My problem came from the
fact that I used the same arraylist as a datasource for my datagridview
and a combobox in the same windows form. As soon as I replace the
datasource of my combobox by a copy of my first arraylist, everything
is working fine. Moreover, if you ever bind a datagridview to an
arraylist, be sure to not bind it until there is at least one element
in your arraylist. If you don't do that and bind your datagridview on
an empty arraylist, after you add the first element in it and click it
in the datagridview, you will end up with the same error message (Index
-1 does not have a value).

Alex.

RobinS a écrit :

RobinS

unread,
Nov 10, 2006, 6:22:19 PM11/10/06
to
Merci beaucoup!
Robin S.

"AlexMich" <alex_mi...@hotmail.com> wrote in message

news:1163194852.9...@f16g2000cwb.googlegroups.com...

AlexMich

unread,
Nov 13, 2006, 10:48:53 AM11/13/06
to
Pas de problème. Ça fait plaisir !

RobinS a écrit :

0 new messages