Results 1 to 7 of 7

Thread: Clearing a form (Reset button)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27

    Clearing a form (Reset button)

    Hello all,

    I have a form with 22 textboxes and 11 labels.
    You can click on a checklistbox with 11 items to activate (make it visible) textboxes and input labels. (i.e. you select Firstname and it sets the text propterty of the first label to "Firstname", textbox1.visible = true and textbox2.visible = true)

    Now, people can enter information in those textboxes (startposition of the field in a record layout and size of the field in a recordlayout)

    Now, people can make mistakes and I wanted to make a reset button. This button should clear the form. I was wondering if there is an easy way to do this? I can't think of anything, but to set the button code to:

    Code:
    Label1.Text = Nothing
    Textbox1.Text = Nothing
    Textbox1.Visible = False
    Label2.Text = Nothing
    Textbox2.Text = Nothing
    Textbox2.Visible = False
    I already created the statement for clearing out the checklistbox, which can be done in a loop...

    Can anyone help me out?
    If you need more info pls let me know!

    Thanks in advance.
    *(^.^); c(_)

  2. #2
    Member
    Join Date
    Mar 2004
    Posts
    39
    You can always have a function that loopes through the form. I often use (as you see in my example) a recursive function where I pass a container control such as a panel or a groupbox to loop through.

    The example is NOT created for your explicit query but just taken from one of my projects as an example of how you might do it:

    Code:
        Public Sub ClearAll(ByVal ControlToClear As Control)
    
            ControlToClear.Enabled = True
    
            For Each conTemp As Control In ControlToClear.Controls
                If TypeOf (conTemp) Is GroupBox Then ClearAll(conTemp)
                If TypeOf (conTemp) Is TextBox Then
                    Dim t As TextBox = conTemp
                    t.Text = ""
                ElseIf TypeOf (conTemp) Is ListView Then
                    Dim l As ListView = conTemp
                    l.Items.Clear()
                End If
            Next
    
        End Sub
    /Nisse

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    Perfect, this is just what I was looking for.

    How would I use this Sub in a button?

    Thanks again...
    Last edited by KoffieMok; Mar 24th, 2004 at 05:55 AM.
    *(^.^); c(_)

  4. #4
    Member
    Join Date
    Mar 2004
    Posts
    39
    For example like this:

    Code:
        Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    
            ClearAll(panNotificationInsuranceID)
            ClearAll(panPersonalInfo)
    
        End Sub
    /Nisse

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    I don't wanna look too dumb, but what is panPersonalInfo and panNotificationInsuranceID?
    A Class? or a Form?
    Or does this loop through the form by itself, so I just add the form name to the ClearAll sub?
    Sorry, I'm pretty new to VB...
    *(^.^); c(_)

  6. #6
    Member
    Join Date
    Mar 2004
    Posts
    39
    No worries. They are in this case panels, but the function works for all types of container controls that I have tried. I have not tried to pass a form, but as that in a sense is also a container control, I think it would work as well to pass a form to the function.

    /Leyan

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Netherlands
    Posts
    27
    This is great, I just tried it with "Me" in the sub, works perfect.
    Thank you very much, great help!
    *(^.^); c(_)

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