Results 1 to 8 of 8

Thread: [RESOLVED] Applying a condition

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    54

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Applying a condition

    Do all 20 have to have something in them in order for the Add/delete/update/ to work?

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    54

    Re: Applying a condition

    yes gentleman all 20 fields have values

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Applying a condition

    Then try something like this. Modify to suit your individual needs.
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim ctrl As Control = Me.GetNextControl(Me, True)
    3.         Do
    4.             If TypeOf ctrl Is TextBox Then
    5.                 If ctrl.Text = String.Empty Then
    6.                     MessageBox.Show("All entires must be complete before running the query.", "Can't Execute Query", _
    7.                     MessageBoxButtons.OK, MessageBoxIcon.Information)
    8.                     Exit Do
    9.                 End If
    10.             End If
    11.             ctrl = Me.GetNextControl(ctrl, True)
    12.         Loop Until ctrl Is Nothing
    13. End Sub

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Applying a condition

    use this function to check any of the values is empty. If empty print the message

    vb Code:
    1. private bool IsEmpty()
    2.         {
    3.               foreach (TextBox txt in this.Controls.OfType<TextBox>())
    4.             {
    5.                 if (string.IsNullOrEmpty(txt.Text))
    6.                 {
    7.                     return false;
    8.                 }
    9.             }
    10.               return true;
    11.         }
    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Applying a condition

    Little slow
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2009
    Posts
    54

    Re: [RESOLVED] Applying a condition

    Thanks for Both answers.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim ctrl As Control = Me.GetNextControl(Me, True)
    3.         Do
    4.             If TypeOf ctrl Is TextBox Then
    5.                 If ctrl.Text = String.Empty Then
    6.                     MessageBox.Show(ctrl.Name & " is empty.  All entires must be complete before running the query.", "Can't Execute Query", _
    7.                     MessageBoxButtons.OK, MessageBoxIcon.Information)
    8.                     ctrl.Focus()  'set focus to the empty textbox
    9.                     Exit Do
    10.                 End If
    11.             End If
    12.             ctrl = Me.GetNextControl(ctrl, True)
    13.         Loop Until ctrl Is Nothing
    14. 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
  •  



Click Here to Expand Forum to Full Width