|
-
Sep 11th, 2003, 06:38 AM
#1
Thread Starter
Junior Member
Enabling/Disabling all of object type on a form
I'm trying to enable/disable all the objects of a certain type on my form, such as all the text boxes. I'm doing this in a similar method to how the proper way to close out of VB 5/6 was.
Here is what I have
dim txt as TextBox
For Each txt in Me
txt.Enabled = False
Next
Now, the Me part doesn't work, so what do I put in place of that so it knows to disable all the text boxes on that form? It's the only form I have so far, and I've tried the form name but it's not working.
Your help is appreciated. Thanks.
-
Sep 11th, 2003, 07:03 AM
#2
Sleep mode
Paste some TextBoxes(or you can choose another control ) on your form and slap this code into one button :
VB Code:
Dim ctl As New Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Enabled = False
End If
Next
-
Sep 11th, 2003, 07:15 AM
#3
Thread Starter
Junior Member
Thanks, it's been a while since I've played around with this. 
Originally posted by Pirate
Paste some TextBoxes(or you can choose another control ) on your form and slap this code into one button :
VB Code:
Dim ctl As New Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Enabled = False
End If
Next
-
Sep 15th, 2003, 01:18 PM
#4
Thread Starter
Junior Member
Ok... For some reason this does not catch all the controls on the form. I was trying to use it to clear the textboxes, (I have text boxes grouped in a groupbox) and am trying to clear all the textboxes in a ClearTextBoxes event. However, it doesn't identify all the textboxes or all the controls when I type the following
dim ctr as control
for each ctr in me.controls
messagebox.show(ctr.name)
next
Last edited by DangerMouse9; Sep 15th, 2003 at 01:25 PM.
-
Sep 15th, 2003, 01:26 PM
#5
use MyBase , not Me as Me points to the item thats holding the controls.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 15th, 2003, 02:40 PM
#6
Thread Starter
Junior Member
I tried myBase and it still only clears out/finds one text box.
-
Sep 15th, 2003, 03:46 PM
#7
Sleep mode
OK , use this instead :
VB Code:
Public Sub clearall()
Dim ctl As New Control
For Each ctl In Me.GroupBox1.Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
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
|