private void txtShipName_Validating(object sender, System.ComponentModel.CancelEventArgs e) { OrderRules BizRule = (OrderRules)this.oOrder.GetBusinessRuleObject(); string Message = BizRule.ValidateShipName(this.txtShipName.Text); if (!mmString.Empty(Message)) { MessageBox.Show(Message); e.Cancel = true; } }And in VB .NET:
Private Sub txtShipName_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Dim BizRule As OrderRules = CType(Me.oOrder.GetBusinessRuleObject(), OrderRules) Dim Message As String = BizRule.ValidateShipName(Me.txtShipName.Text) If Not mmString.Empty(Message) Then MessageBox.Show(Message) e.Cancel = True End If End SubHere's one extra tidbit...if your business rule objects are using "Error Provider" style broken rules, you need to perform an additional check in your rule object method to determine if the rule method was called directly, or via CheckRules. This can be determined by checking if the DataSet property is null:
public string ValidateShipName(string shipName) { string message = null; if (shipName == "") { message = "Must specify a ship name"; if (this.DataSet != null) { this.AddErrorProviderBrokenRule("ShipName", message); } } return message; }And in VB .NET:
Public Function ValidateShipName(shipName As String) As String Dim message As String = Nothing If shipName = "" Then message = "Must specify a ship name" If Not (Me.DataSet Is Nothing) Then Me.AddErrorProviderBrokenRule("ShipName", message) End If End If Return message End FunctionI've made a change that will come out in the next version of MM .NET that won't require you to perform this additional check, but for now, you need to do it in methods that you are calling directly IF you are using the Error Provider-style broken rule messages.