need help with error message

T

TJS

When trying to delete a row from a datagrid I get this error on every record
regardless of record selected to delete.
"Index 7 is not non-negative and below total rows count."

there are 8 rows in the table being edited so index 7 should be a valid
number

========= the offending code =================

Private _dataGridData As New DataTable()
Private _dataGridView As New DataView()
......

Private Sub DeleteRow(rowIndex As Integer)

_dataGridView = _dataGridData.DefaultView

If _dataGridData.Rows.Count >= rowIndex Then
' Delete row from datatable
Dim row As DataRow = _dataGridView(rowIndex).Row
row.Delete() '<=== won't go past this point
End If

End sub
 
P

pj

When trying to delete a row from a datagrid I get this error on every record
regardless of record selected to delete.
"Index 7 is not non-negative and below total rows count."

there are 8 rows in the table being edited so index 7 should be a valid
number

Are there 8 rows in the DataView as well? Perhaps you have a filter in
place and _dataGridData.DefaultView has fewer rows than
_dataGridData.

pj
 
T

TJS

I don't know how to confirm that ..



pj said:
Are there 8 rows in the DataView as well? Perhaps you have a filter in
place and _dataGridData.DefaultView has fewer rows than
_dataGridData.

pj
 
T

TJS

thanks for replying ..

I found the problem , it was looking for a primary key field, which was
missing from the query.
the error message was not very helpful in this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top