Validation not running

Validation not running

Old forum URL: forums.lhotka.net/forums/t/2774.aspx


FCazabon posted on Wednesday, April 25, 2007

Hi,

I'm creating my first Windows UI (first time using Visual Studio and CSLA).

I'm using VB and am trying to create a simple interface to a Member BO and table.

My Member BO has this code:

    Public Property Mem_FirstName() As String
        <System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
        Get
            CanReadProperty(True)
            Return mMem_FirstName
        End Get
        <System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
        Set(ByVal Value As String)
            CanWriteProperty(True)
            If mMem_FirstName <> Value Then
                mMem_FirstName = Value
                PropertyHasChanged()
            End If
        End Set
    End Property

and also:

    Protected Overrides Sub AddBusinessRules()

        ValidationRules.AddRule( _
          AddressOf Validation.CommonRules.StringRequired, "mem_FirstName")

    End Sub

When I edit a first name, deleting all the text, then tabbing to the next control, I do not get the icon indicating a rule has been broken.

I set a breakpoint on the call to PropertyHasChanged(), but I do not get the option to "Step into" this code, only "Step over".

Any ideas what I have done wrong and how to step into the PropertyHasChanged subroutine?

Thanks,

Frank

skagen00 replied on Wednesday, April 25, 2007

One thing that jumps out at me is that your rule doesn't have the same casing (mem_FirstName vs Mem_FirstName). I'm not sure if it matters to be honest with you but I'd guess that it does.

FCazabon replied on Wednesday, April 25, 2007

Thanks!

that was it.  I didn't think VB had to be case sensitive, but I guess this might actualy be CSLA, not VB.

Now, if only I could work out how to set focus to the first textbox on a form  automatically when the form is initially displayed... :)

xal replied on Wednesday, April 25, 2007

Adjust the "TabIndex" property of each of your controls to be in the order you want.

Andrés

FCazabon replied on Wednesday, April 25, 2007

Hi Andres,

I have tried that and it doesn't work.  You can see the same thing in the Project Tracker sample.  If you edit the ProjectEdit.vb and set the tab order of the Nametextbox, then run the sample, add a new project and you will see that the focus seems to be somewhere magical as typing any text does nothing.  Press Tab and the focus then goes to the NameTextbox, shift and Tab and ot goes to the Close button.

xal replied on Wednesday, April 25, 2007

TabIndex starts at zero, make sure your first control has that value assigned. Also, you can set 2 controls to the same value, so watch that no other control ahs that same value!!

Andrés

FCazabon replied on Wednesday, April 25, 2007

I had it set to zero (and it was the only one set to zero) and that still wouldn't work.

I looked at the code in the LoginForm and saw that it specifically set the focus to the UserNameTextbox so I did likewise in my MemberEdit.vb:

  Private Sub MemberEdit_Load( _
    ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load

    Me.Mem_FirstNamenameTextBox.Focus()

  End Sub


That seems to do the trick.

skagen00 replied on Wednesday, April 25, 2007

Yeah, there's nothing "Csla" related about thie string comparison issue you bumped into. Generally two strings are equal when taking into account case sensitivity. (Though the property checks I suppose could be done without case sensitivity)

Glad I could help.

Copyright (c) Marimer LLC