Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating form fields

Status
Not open for further replies.

paullem

Programmer
Jan 21, 2005
80
0
0
GB
Hi,

I'm pretty new to vb 2005 and finding things that were straight forward in VB6 are difficult to fathom in vb 2005. One such thing is validation of form fields. I have a field where the validation takes place in the validating event but I want the form Cancel button to ignore all vailidation and exit the form. I have put 'Me.cmdCancel.CausesValidation = False' in the form Load event but this does not seem to work. The validation code is:

Private Sub txtTitle_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtTitle.Validating

If (IsNothing(Me.txtTitle.Text)) Or (Me.txtTitle.Text = "") Then
MsgBox("Enter a valid Pin Board item Title", MsgBoxStyle.Exclamation)
Me.txtTitle.Focus()
Exit Sub
End If

End Sub

I would be grateful for any help. Many thanks.
 
hi
i have tried your code and it works ok for me! the form closes on button click without validation!
The only difference was that i set the button.causesValidation property in the property page and put End in the button.click handler.
you may have some other code that is causing the problem!
publish the whole form code here so we can see.
reg1965
 
Hi, the form is a modal form that accepts updates an refreshes a datagrid on the calling form. The only way I found to achieve this was to call the modal form using code:

Dim frmDialogue As New frmPinBoardAddItem
If frmDialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.TblPinBoardTableAdapter.Fill(Me.IMSDataSet.tblPinBoard)
Me.DataGridView1.Refresh()
Me.Refresh()
End If

Then in the modal form the cancel button contains the code:

Me.DialogResult = Windows.Forms.DialogResult.Cancel

and the accept button contains the code:

Me.DialogResult = Windows.Forms.DialogResult.OK

If I show and close the form in the normal way the cancel button does not cause validation. To get round the problem I've moved all the validation into the accept button.

Hope this makes sense? Thanks for your help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top