Skip to main content

I get an error accessing the data grid that the index is out of range. I have done this many times so the error is unusual. The only factor different in my many uses of data grid is that I have two data grids on a single form. I'll provide some detail.

Here is the code

invoke self::dataGridView2::Rows::Clear
set dataGridView2::ColumnCount = 3
set dataGridView2::Columns[0]::Width = 100 *> Hole
set dataGridView2::Columns[1]::Width = 150 *> player
set dataGridView2::Columns[2]::Width = 100 *> results

perform varying sub1 from 1 by 1 until sub1 > 9
   subtract 1 from sub1 giving line-number (this gives zero)
   move 0 to column-index
   set dataGridView2::CurrentCell = dataGridView2::Rows[line-number]::Cells[column-index];

The above set datagridview2 fails with 

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection

The following (if you can see it) to me indicates line-number and column-index are correct

Any help? 


#VisualCOBOL

I get an error accessing the data grid that the index is out of range. I have done this many times so the error is unusual. The only factor different in my many uses of data grid is that I have two data grids on a single form. I'll provide some detail.

Here is the code

invoke self::dataGridView2::Rows::Clear
set dataGridView2::ColumnCount = 3
set dataGridView2::Columns[0]::Width = 100 *> Hole
set dataGridView2::Columns[1]::Width = 150 *> player
set dataGridView2::Columns[2]::Width = 100 *> results

perform varying sub1 from 1 by 1 until sub1 > 9
   subtract 1 from sub1 giving line-number (this gives zero)
   move 0 to column-index
   set dataGridView2::CurrentCell = dataGridView2::Rows[line-number]::Cells[column-index];

The above set datagridview2 fails with 

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection

The following (if you can see it) to me indicates line-number and column-index are correct

Any help? 


#VisualCOBOL
invoke self::dataGridView2::Rows::Clear
...
set dataGridView2::CurrentCell = dataGridView2::Rows[line-number]::Cells[column-index];

You have cleared all the rows.

I get an error accessing the data grid that the index is out of range. I have done this many times so the error is unusual. The only factor different in my many uses of data grid is that I have two data grids on a single form. I'll provide some detail.

Here is the code

invoke self::dataGridView2::Rows::Clear
set dataGridView2::ColumnCount = 3
set dataGridView2::Columns[0]::Width = 100 *> Hole
set dataGridView2::Columns[1]::Width = 150 *> player
set dataGridView2::Columns[2]::Width = 100 *> results

perform varying sub1 from 1 by 1 until sub1 > 9
   subtract 1 from sub1 giving line-number (this gives zero)
   move 0 to column-index
   set dataGridView2::CurrentCell = dataGridView2::Rows[line-number]::Cells[column-index];

The above set datagridview2 fails with 

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection

The following (if you can see it) to me indicates line-number and column-index are correct

Any help? 


#VisualCOBOL
I do a clear before the definition of the grid (in all of my programs). I noted out the clear and get the same results. Thanks, I've tried about everything

I get an error accessing the data grid that the index is out of range. I have done this many times so the error is unusual. The only factor different in my many uses of data grid is that I have two data grids on a single form. I'll provide some detail.

Here is the code

invoke self::dataGridView2::Rows::Clear
set dataGridView2::ColumnCount = 3
set dataGridView2::Columns[0]::Width = 100 *> Hole
set dataGridView2::Columns[1]::Width = 150 *> player
set dataGridView2::Columns[2]::Width = 100 *> results

perform varying sub1 from 1 by 1 until sub1 > 9
   subtract 1 from sub1 giving line-number (this gives zero)
   move 0 to column-index
   set dataGridView2::CurrentCell = dataGridView2::Rows[line-number]::Cells[column-index];

The above set datagridview2 fails with 

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection

The following (if you can see it) to me indicates line-number and column-index are correct

Any help? 


#VisualCOBOL
Have you set the AllowUserToAddRows property to False?
If yes, and you call the clear method, then you need to add a row after adding some columns.

I get an error accessing the data grid that the index is out of range. I have done this many times so the error is unusual. The only factor different in my many uses of data grid is that I have two data grids on a single form. I'll provide some detail.

Here is the code

invoke self::dataGridView2::Rows::Clear
set dataGridView2::ColumnCount = 3
set dataGridView2::Columns[0]::Width = 100 *> Hole
set dataGridView2::Columns[1]::Width = 150 *> player
set dataGridView2::Columns[2]::Width = 100 *> results

perform varying sub1 from 1 by 1 until sub1 > 9
   subtract 1 from sub1 giving line-number (this gives zero)
   move 0 to column-index
   set dataGridView2::CurrentCell = dataGridView2::Rows[line-number]::Cells[column-index];

The above set datagridview2 fails with 

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Additional information: Index was out of range. Must be non-negative and less than the size of the collection

The following (if you can see it) to me indicates line-number and column-index are correct

Any help? 


#VisualCOBOL
Thanks for your answers but the error was created by me doing things in a different order. Every other time I've populated the grid with Invoke Self::dataGridView1::Rows::Add. But I by passed that step.