Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help!!! on getting control over Controls on VB.Net Forms

Help!!! on getting control over Controls on VB.Net Forms

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Het2109
    wrote on last edited by
    #1

    How to get all the controls in the form, like in VB we used to do for each ctrl in me if typeof ctrl is Textbox then ctrl.text = "" end if next How we do this in VB.Net.??? Thanks :)Be Humble in Victory and Strong in Defeat.:) -Het

    C 1 Reply Last reply
    0
    • H Het2109

      How to get all the controls in the form, like in VB we used to do for each ctrl in me if typeof ctrl is Textbox then ctrl.text = "" end if next How we do this in VB.Net.??? Thanks :)Be Humble in Victory and Strong in Defeat.:) -Het

      C Offline
      C Offline
      Corinna John
      wrote on last edited by
      #2

      The controls are in me.Controls. for each ctl as Control in me.Controls if TypeOf ctl Is TextBox Then ... next

      H 1 Reply Last reply
      0
      • C Corinna John

        The controls are in me.Controls. for each ctl as Control in me.Controls if TypeOf ctl Is TextBox Then ... next

        H Offline
        H Offline
        Het2109
        wrote on last edited by
        #3

        was good one controls are in me, but, I tried out the code, i declared ctl as object, and gave the same code but it is giving me "syntax error ." thats what it is saying. so if u can help me out. Thanks again for ur reply :)Be Humble in Victory and Strong in Defeat.:) -Het

        C I 2 Replies Last reply
        0
        • H Het2109

          was good one controls are in me, but, I tried out the code, i declared ctl as object, and gave the same code but it is giving me "syntax error ." thats what it is saying. so if u can help me out. Thanks again for ur reply :)Be Humble in Victory and Strong in Defeat.:) -Het

          C Offline
          C Offline
          Corinna John
          wrote on last edited by
          #4

          ctl should to be Control, not Object. I tried this, without any errors: For Each ctl As Control In Me.Controls ctl.Text = "hier" Next

          1 Reply Last reply
          0
          • H Het2109

            was good one controls are in me, but, I tried out the code, i declared ctl as object, and gave the same code but it is giving me "syntax error ." thats what it is saying. so if u can help me out. Thanks again for ur reply :)Be Humble in Victory and Strong in Defeat.:) -Het

            I Offline
            I Offline
            Ian Darling
            wrote on last edited by
            #5

            Het2109 wrote: giving me "syntax error I tested that code myself in VB.NET

            As [type]" syntax won't work try:

                    Dim c As Control
                    For Each c In Me.Controls
                        If TypeOf c Is TextBox Then
            
                        End If
                    Next
            

            -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

            H 1 Reply Last reply
            0
            • I Ian Darling

              Het2109 wrote: giving me "syntax error I tested that code myself in VB.NET

              As [type]" syntax won't work try:

                      Dim c As Control
                      For Each c In Me.Controls
                          If TypeOf c Is TextBox Then
              
                          End If
                      Next
              

              -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

              H Offline
              H Offline
              Het2109
              wrote on last edited by
              #6

              ya, but suppose i have a group box and my textbox/combo box is placed on the group box, then how to access it. thru this code i get groupbox, but not the controls that are placed inside the groupbox. :)Be Humble in Victory and Strong in Defeat.:) -Het

              I 1 Reply Last reply
              0
              • H Het2109

                ya, but suppose i have a group box and my textbox/combo box is placed on the group box, then how to access it. thru this code i get groupbox, but not the controls that are placed inside the groupbox. :)Be Humble in Victory and Strong in Defeat.:) -Het

                I Offline
                I Offline
                Ian Darling
                wrote on last edited by
                #7

                Het2109 wrote: ya, but suppose i have a group box and my textbox/combo box is placed on the group box, then how to access it. thru this code i get groupbox, but not the controls that are placed inside the groupbox. Then handle that case in the loop, either by having a secondary loop, or better, set up the loop as a function that takes a controls collection as a parameter. eg:

                    Public Sub RecurseControls(ByVal ctls As ControlCollection)
                
                        Dim c As Control
                        For Each c In ctls
                            If TypeOf c Is TextBox Then
                                Debug.WriteLine(c.Text)
                            ElseIf TypeOf c Is GroupBox Then
                                RecurseControls(c.Controls)
                            End If
                        Next
                
                    End Sub
                

                You call this function, passing in Me.Controls to start with. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups