R
Rick
I have the recursive function below which I use to find a datagridview with
a certain bindingsource.
When the grid is parented by a control with only one child (the dgv) the
function works ok, but when there are multiple controls the function calls
itself and eventually returns "Nothing" if the dgv is not the last control.
How can I short circuit this function so that once it finds my target it
exits for good? Do I need some other kind of function and a recursive one?
Rick
Private Function FindDGV(ByVal parent As Control) As DataGridView
Dim dgv As DataGridView
FindDGV = dgv
Dim ctrl As Control
For Each ctrl In parent.Controls
If (ctrl.GetType Is GetType(DataGridView)) AndAlso _
DirectCast(ctrl,
DataGridView).DataSource.Equals(Nav.BindingSource) Then
Return DirectCast(ctrl, DataGridView)
Else
If ctrl.Controls.Count > 0 Then FindDGV(ctrl)
End If
End Function
a certain bindingsource.
When the grid is parented by a control with only one child (the dgv) the
function works ok, but when there are multiple controls the function calls
itself and eventually returns "Nothing" if the dgv is not the last control.
How can I short circuit this function so that once it finds my target it
exits for good? Do I need some other kind of function and a recursive one?
Rick
Private Function FindDGV(ByVal parent As Control) As DataGridView
Dim dgv As DataGridView
FindDGV = dgv
Dim ctrl As Control
For Each ctrl In parent.Controls
If (ctrl.GetType Is GetType(DataGridView)) AndAlso _
DirectCast(ctrl,
DataGridView).DataSource.Equals(Nav.BindingSource) Then
Return DirectCast(ctrl, DataGridView)
Else
If ctrl.Controls.Count > 0 Then FindDGV(ctrl)
End If
End Function