By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Removing an item in a collection causes System.ArgumentOutOfRangeException error

P: n/a
Hi,

I have a collection object bound to a data grid, after I remove an
item from the collection, the minute I click on the datagrid I get an
error saying the specified argument was out of the range of valid
values.

After I remove the element from the collection I clear the
databindings from the data grid and rebind it but as far as I can tell
the collection seems to be the right size but for some reason when I
rebind the datagrid it still sees the original number of elements in
the collection.

Should the collection not dynamicaly resize when an item is removed or
does it just grow and if something is removed it doesn't reduce in
size.

Below is the code I used to remove and rebind the collection to the
datagrid and the error message I get after removing and item and
clicking on the datagrid.

Any assistance would be aprreciated.

Thanks

Mike

int iRow = dgLabs.CurrentRowIndex;

labtests.RemoveAt (iRow);

dgLabs.DataBindings.Clear();
dgLabs.DataSource = null;
dgLabs.DataSource = labtests;
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the
array.
at System.Windows.Forms.DataGrid.Edit(String instantText)
at System.Windows.Forms.DataGrid.Edit()
at System.Windows.Forms.DataGrid.OnEnter(EventArgs e)
at System.Windows.Forms.Control.NotifyEnter()
at System.Windows.Forms.ContainerControl.UpdateFocuse dControl()
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/
mscorlib.dll
----------------------------------------
HopeStats
Assembly Version: 1.0.2599.15106
Win32 Version: 1.0.2599.15106
CodeBase: file:///C:/data/Visual%20Studio%20Projects/Transplant
%20Statistics/HopeStats/bin/Debug/HopeStats.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/
1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system/
1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Data
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.data/
1.0.5000.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.xml/
1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.drawing/
1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
CustomValidation
Assembly Version: 1.0.2599.15065
Win32 Version: 1.0.2599.15065
CodeBase: file:///C:/data/Visual%20Studio%20Projects/Transplant
%20Statistics/HopeStats/bin/Debug/CustomValidation.DLL
----------------------------------------
ConnectionStrings
Assembly Version: 1.0.2530.19825
Win32 Version: 1.0.2530.19825
CodeBase: file:///C:/data/Visual%20Studio%20Projects/Transplant
%20Statistics/HopeStats/bin/Debug/ConnectionStrings.DLL
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.

Feb 12 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.