|
-
Oct 20th, 2009, 06:09 AM
#1
Thread Starter
Member
[RESOLVED] Applying a condition
I have add,update,delete buttons on my form.A message box should appear on the screen "should have values to Add/delete/update/" if user clicks on Add/delete/update buttons without having any values in the textfiled,i have around 20 text fields on my form.
-
Oct 20th, 2009, 06:11 AM
#2
Re: Applying a condition
Do all 20 have to have something in them in order for the Add/delete/update/ to work?
-
Oct 20th, 2009, 06:13 AM
#3
Thread Starter
Member
Re: Applying a condition
yes gentleman all 20 fields have values
-
Oct 20th, 2009, 06:25 AM
#4
Re: Applying a condition
Then try something like this. Modify to suit your individual needs.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ctrl As Control = Me.GetNextControl(Me, True)
Do
If TypeOf ctrl Is TextBox Then
If ctrl.Text = String.Empty Then
MessageBox.Show("All entires must be complete before running the query.", "Can't Execute Query", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Do
End If
End If
ctrl = Me.GetNextControl(ctrl, True)
Loop Until ctrl Is Nothing
End Sub
-
Oct 20th, 2009, 06:27 AM
#5
Re: Applying a condition
use this function to check any of the values is empty. If empty print the message
vb Code:
private bool IsEmpty() { foreach (TextBox txt in this.Controls.OfType<TextBox>()) { if (string.IsNullOrEmpty(txt.Text)) { return false; } } return true; }
Please mark you thread resolved using the Thread Tools as shown
-
Oct 20th, 2009, 06:28 AM
#6
Re: Applying a condition
Little slow
Please mark you thread resolved using the Thread Tools as shown
-
Oct 20th, 2009, 06:32 AM
#7
Thread Starter
Member
Re: [RESOLVED] Applying a condition
-
Oct 20th, 2009, 08:04 AM
#8
Re: [RESOLVED] Applying a condition
If you want, you can add ctrl.Name to the messagebox and tell them which textbox needs to be addressed and then set focus to it.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ctrl As Control = Me.GetNextControl(Me, True)
Do
If TypeOf ctrl Is TextBox Then
If ctrl.Text = String.Empty Then
MessageBox.Show(ctrl.Name & " is empty. All entires must be complete before running the query.", "Can't Execute Query", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
ctrl.Focus() 'set focus to the empty textbox
Exit Do
End If
End If
ctrl = Me.GetNextControl(ctrl, True)
Loop Until ctrl Is Nothing
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|