opensubscriber
   Find in this group all groups
 
Unknown more information…

d : dotnet-winforms@discuss.develop.com 27 January 2008 • 9:55PM -0500

Negative rowIndex for new DataGridViewRow
by Brady Kelly

REPLY TO AUTHOR
 
REPLY TO GROUP




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?



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

            newRow.CreateCells(dgvLayout);

            dgvLayout.Rows.Add(newRow);



            int cx = 0;

            foreach (Column o in newLIne.RecordLayout.Columns.Values)

            {

                int rowIndex = dgvLayout.Rows.Count - 1;

                dgvLayout.Rows[rowIndex].Cells[cx].Value = o.ColumnValue;

                //DataGridViewCell c = newRow.Cells[cx];

                //newRow.Cells[cx].Value = o.ColumnValue;

                cx++;

            }

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

opensubscriber is not affiliated with the authors of this message nor responsible for its content.