Monday, August 31, 2015

Negative rowIndex for a DataGridViewRow

Negative rowIndex problem for new DataGridViewRow

I create and add a new row to an unbound DataGridView.  Then, if I try and
access an item in the Cells collection of the row, as in my commented out
code, I get an index out of range exception, rowIndex.  I'm not specifying a
row index, so I assume it is inferring it from the row object, whose
rowIndex property is -1.  However, when I access the cell through a row in
the grids Rows collection, I'm happy, as in my other code.  Can anyone
explain this behaviour?

The exception:

Specified argument was out of the range of valid values.

Parameter name: rowIndex

The code:

            ExportLineRow newRow = new ExportLineRow(); // Derived from
DataGridViewRows.

            newRow.ExportLine = newLIne;

            newRow.CreateCells(dgvLayout);

            dgvLayout.Rows.Add(newRow);

            int cx = 1;

            foreach (Column o in
newRow.ExportLine.RecordLayout.Columns.Values)

Re: Negative rowIndex problem for new DataGridViewRow

Hi Brady,

With the DataGridView, the rows could be accessed iteratively up to a
size of myGrid.Rows.Count

Here is a webpage with an example of how to access a row/column
reference as you describe.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.rowcount.aspx

On Jan 27, 2008 1:00 PM, Brady Kelly <brady <at> chasesoftware.co.za> wrote:
> I create and add a new row to an unbound DataGridView.  Then, if I try and
> access an item in the Cells collection of the row, as in my commented out
> code, I get an index out of range exception, rowIndex.  I'm not specifying a
> row index, so I assume it is inferring it from the row object, whose
> rowIndex property is -1.  However, when I access the cell through a row in
> the grids Rows collection, I'm happy, as in my other code.  Can anyone
> explain this behaviour?
>
>
>
> The exception:
>
>
>
> Specified argument was out of the range of valid values.
>
> Parameter name: rowIndex
>
>

Re: Negative rowIndex problem for new DataGridViewRow

Hi Kara,

Thanks for the link, but I've determined my problem is somehow related to me
trying to add row objects derived from DataGridViewRow.  I suspect I'm not
overriding a required member somewhere, because I can add one custom row,
but all other rows after that break when I add them.

>
> Hi Brady,
>
> With the DataGridView, the rows could be accessed iteratively up to a
> size of myGrid.Rows.Count
>
>
> Here is a webpage with an example of how to access a row/column
> reference as you describe.
>
> http://msdn2.microsoft.com/en-
> us/library/system.windows.forms.datagridview.rowcount.aspx

Re: Negative rowIndex problem for new DataGridViewRow

Brady

DId that work?  If not, could you zip up the part of your code with
the data grid view and email it to my email address

kara.hewett <at> gmail.com

I'll debug the code to see what's going on.

kara

On Jan 27, 2008 1:00 PM, Brady Kelly <brady <at> chasesoftware.co.za> wrote:
> I create and add a new row to an unbound DataGridView.  Then, if I try and
> access an item in the Cells collection of the row, as in my commented out
> code, I get an index out of range exception, rowIndex.  I'm not specifying a
> row index, so I assume it is inferring it from the row object, whose
> rowIndex property is -1.  However, when I access the cell through a row in
> the grids Rows collection, I'm happy, as in my other code.  Can anyone
> explain this behaviour?
>
>
>
> The exception:
>
>
>
> Specified argument was out of the range of valid values.
>
> Parameter name: rowIndex
>

No comments:

Post a Comment