Negative rowIndex problem for new DataGridViewRow
Brady Kelly <brady <at> CHASESOFTWARE.CO.ZA>
2008-01-27 18:00:34 GMT
2008-01-27 18:00:34 GMT
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
kara hewett <kara.hewett <at> GMAIL.COM>
2008-01-27 22:36:09 GMT
2008-01-27 22:36:09 GMT
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
Brady Kelly <brady <at> CHASESOFTWARE.CO.ZA>
2008-01-27 23:06:58 GMT
2008-01-27 23:06:58 GMT
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
kara hewett <kara.hewett <at> GMAIL.COM>
2008-01-27 22:55:58 GMT
2008-01-27 22:55:58 GMT
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