nyarlathotep
Member
- Joined
- Mar 23, 2012
- Messages
- 6
- Programming Experience
- 1-3
I've written some code which attempts to hide all rows in to a bound datagridview (dvg1) which share values in a column called sch_id with rows in an unbound datagridview (dvg2). It works for drag operations, the dragged rows are hidden once they are dropped to dvg2.
When a sort action is applied to dvg1 The code is triggered by dvg1.DataBindingComplete. If one of the rows to hide is the first row of dvg1 it throws an error.
This is because something sets the currentrow to the first row, which I've just hidden, after this sub has run. Is there a way out of this?
When a sort action is applied to dvg1 The code is triggered by dvg1.DataBindingComplete. If one of the rows to hide is the first row of dvg1 it throws an error.
This is because something sets the currentrow to the first row, which I've just hidden, after this sub has run. Is there a way out of this?
VB.NET:
Private Sub hide_used_rows(ByVal dvg1 As DataGridView, ByVal dvg2 As DataGridView)
Dim hide_list(dvg1.Rows.Count - 1) As Integer
Dim i As Integer
Dim j As Integer = -1
dvg2.CurrentCell = Nothing
For Each row2 As DataGridViewRow In dvg2.Rows
For Each row1 As DataGridViewRow In dvg1.Rows
If row1.Cells(GetColName("sch_id", dvg1)).Value() = row2.Cells(GetColName("sch_id", dvg2)).Value() Then
hide_list(row1.Index) = 1
End If
Next
Next
For i = 0 To (dvg1.Rows.Count - 1)
If hide_list(i) <> 1 Then
dvg1.Rows(i).Visible = True
If j = -1 Then j = i
End If
Next
For i = 0 To dvg1.Rows.Count - 1
If hide_list(i) = 1 Then
Try
If dvg1.CurrentCell.RowIndex = i Then
dvg1.CurrentCell = dvg1(1, j)
End If
Catchng)
dvg1.CurrentCell = dvg1(1, j)
Finally
dvg1.Rows(i).Visible = False
End Try
End If
Next
End Sub