Appframe Knowledge Base

1 hits

How to locate a control bound to a specific fieldname

Private Shared Function FindBoundControl(ByVal fieldName As String, ByVal ctrl As Control) As Control
        If ctrl.DataBindings.Count > 0 AndAlso ctrl.DataBindings(0).BindingMemberInfo.BindingField = fieldName Then
            Return ctrl
        End If
        For Each child As Control In ctrl.Controls
            If child.DataBindings.Count > 0 AndAlso child.DataBindings(0).BindingMemberInfo.BindingField = fieldName Then
                Return child
            End If
            Dim childResult As Control = FindBoundControl(fieldName, child)
            If childResult IsNot Nothing Then
                Return childResult
            End If
        Return Nothing
    End Function

common win · Perma link post comment Posted by: Stian Gundersen Skjerveggen (22-aug-2012)