Results 1 to 7 of 7

Thread: Enabling/Disabling all of object type on a form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    26

    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.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Paste some TextBoxes(or you can choose another control ) on your form and slap this code into one button :

    VB Code:
    1. Dim ctl As New Control
    2.         For Each ctl In Me.Controls
    3.             If TypeOf ctl Is TextBox Then
    4.                 ctl.Enabled = False
    5.             End If
    6.         Next

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    26
    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:
    1. Dim ctl As New Control
    2.         For Each ctl In Me.Controls
    3.             If TypeOf ctl Is TextBox Then
    4.                 ctl.Enabled = False
    5.             End If
    6.         Next

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    26
    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.

  5. #5
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    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]

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    26
    I tried myBase and it still only clears out/finds one text box.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    OK , use this instead :
    VB Code:
    1. Public Sub clearall()
    2.         Dim ctl As New Control
    3.  
    4.         For Each ctl In Me.GroupBox1.Controls
    5.             If TypeOf ctl Is TextBox Then
    6.                 ctl.Text = ""
    7.             End If
    8.         Next
    9.  
    10.         For Each ctl In Me.Controls
    11.             If TypeOf ctl Is TextBox Then
    12.                 ctl.Text = ""
    13.             End If
    14.         Next
    15.  
    16.     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