|
-
Mar 24th, 2004, 02:54 AM
#1
Thread Starter
Junior Member
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.
-
Mar 24th, 2004, 05:17 AM
#2
Member
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
-
Mar 24th, 2004, 05:45 AM
#3
Thread Starter
Junior Member
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(_)
-
Mar 24th, 2004, 05:57 AM
#4
Member
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
-
Mar 24th, 2004, 06:08 AM
#5
Thread Starter
Junior Member
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...
-
Mar 24th, 2004, 07:11 AM
#6
Member
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
-
Mar 24th, 2004, 07:16 AM
#7
Thread Starter
Junior Member
This is great, I just tried it with "Me" in the sub, works perfect.
Thank you very much, great help!
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
|