Hi
I wonder if anyone could help with this issue. I have an unbound datagridview from which I am trying to remove the top half of all the rows. Currently I am doing this:
<CODE>
Dim totalRows As Short = dataGridView.Rows.Count
For Each indexRow As DataGridViewRow In dataGridView.Rows
indexRow.Cells(9).Value = indexRow.Index
Next
For Each deleteRow As DataGridViewRow In dataGridView.Rows
'If deleteRow.Cells(9).Value < totalRows / 2 Then dataGridView.Rows.Remove(deleteRow)
If deleteRow.Cells(9).Value < totalRows / 2 Then deleteRow.Cells(1).Value = "DELETE"
Next
dataGridView.Sort(dataGridView.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
</CODE>
This works in as much as it correctly identifies the rows meant for deletion, and marks them on the screen with "DELETE". However, if I comment out this line and instead uncomment the line above it which is actually meant to perform the deletion, I get an unhandled exception.
ArgumentOutOfRangeException was unhandled
Row index provided is out of range
Parameter name: rowindex
No Source Available
No symbols are loaded for any call stack frame. The source code cannot be displayed.
The code above is contained within a try-catch block, so to get an unhandled exception I think it must have occured deeper down in the class framework than I can see the code for.
I've been struggling with this for a while, so I would appreciate it if anyone has any ideas.
Thanks
I wonder if anyone could help with this issue. I have an unbound datagridview from which I am trying to remove the top half of all the rows. Currently I am doing this:
<CODE>
Dim totalRows As Short = dataGridView.Rows.Count
For Each indexRow As DataGridViewRow In dataGridView.Rows
indexRow.Cells(9).Value = indexRow.Index
Next
For Each deleteRow As DataGridViewRow In dataGridView.Rows
'If deleteRow.Cells(9).Value < totalRows / 2 Then dataGridView.Rows.Remove(deleteRow)
If deleteRow.Cells(9).Value < totalRows / 2 Then deleteRow.Cells(1).Value = "DELETE"
Next
dataGridView.Sort(dataGridView.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
</CODE>
This works in as much as it correctly identifies the rows meant for deletion, and marks them on the screen with "DELETE". However, if I comment out this line and instead uncomment the line above it which is actually meant to perform the deletion, I get an unhandled exception.
ArgumentOutOfRangeException was unhandled
Row index provided is out of range
Parameter name: rowindex
No Source Available
No symbols are loaded for any call stack frame. The source code cannot be displayed.
The code above is contained within a try-catch block, so to get an unhandled exception I think it must have occured deeper down in the class framework than I can see the code for.
I've been struggling with this for a while, so I would appreciate it if anyone has any ideas.
Thanks