StrataFrame Forum

Tab focus for error provider

http://forum.strataframe.net/Topic1919.aspx

By Andria Jensen - 7/21/2006

If I have a form with multiple tabs on it, and there is an error on a tab not focused...is there a way to focus the tab with the error on it automatically?
By Trent L. Taylor - 7/21/2006

Right now there is not a way to do this automatically.  But you can tie this in failry easy.  Below is a sample of one possible way to achieve this.  I did not test this code, but you should get the general idea.

Private Sub MyBO_BusinessRulesChecked(ByVal e As MicroFour.StrataFrame.Business.BusinessRulesCheckedEventArgs) Handles MyBO.BusinessRulesChecked

'-- Establish Locals
Dim loRule As MicroFour.StrataFrame.Business.BrokenRule
Dim loControl As System.Windows.Forms.Control

If e.CountOfBrokenRulesTotal > 0 Then

'-- Get the first broken rule
loRule = MyBO.BrokenRules.ToArray()(0)

'-- Cycle through all of the controls on the form
For Each loControl In Me.Controls
    '-- See if the control supports the IBusinessBindable interface (SF Binding)
   
If loControl.GetType().GetInterface("IBusinessBindable") IsNot Nothing Then

        '-- See if the control matches the field name in error
       
If CType(loControl, MicroFour.StrataFrame.UI.Windows.Forms.IBusinessBindable).BindingField.Equals(loRule.FieldName, StringComparison.OrdinalIgnoreCase) Then

            '-- Set the focus
           
loControl.Focus()

            '-- Exit the loop
           
Exit For

        End If
    End If
Next

End If

End Sub

By Andria Jensen - 7/21/2006

Thanks Trent, I'll give that a try.
By Trent L. Taylor - 7/21/2006

Sure.  Like I said, I did not test the code and you might have to make minor change here or there, but this should at least get you started.