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. With just the name of a RadioButton, how can I check/uncheck the control?

With just the name of a RadioButton, how can I check/uncheck the control?

Scheduled Pinned Locked Moved Visual Basic
question
6 Posts 2 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.
  • S Offline
    S Offline
    Steve van Niman
    wrote on last edited by
    #1

    I'm trying to do a mapping exercise and if a user clicks on a column and it has already been mapped, I want to check the corresponding radio button. If I use a For Each loop to loop through the controls of a group box, I can find the control/radio button, I can change the Text, Font size, position and many other things, but I cannot change the Checked status. What am I missing? Thanks in advance, Steve

    L 1 Reply Last reply
    0
    • S Steve van Niman

      I'm trying to do a mapping exercise and if a user clicks on a column and it has already been mapped, I want to check the corresponding radio button. If I use a For Each loop to loop through the controls of a group box, I can find the control/radio button, I can change the Text, Font size, position and many other things, but I cannot change the Checked status. What am I missing? Thanks in advance, Steve

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      AFAIK you can get and set RadioButton.Checked; setting it might fail if it is disabled. And then there is RadioButton.PerformClick() :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


      S 1 Reply Last reply
      0
      • L Luc Pattyn

        AFAIK you can get and set RadioButton.Checked; setting it might fail if it is disabled. And then there is RadioButton.PerformClick() :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


        S Offline
        S Offline
        Steve van Niman
        wrote on last edited by
        #3

        AFAIK? Was able to get to the Checked property by converting the Control to a Radio Button using CType.

        Private Sub ChecktheRadioButton(ByVal sName as String)

        Dim ctr as Control
        For Each ctr in GroupBox2.Controls
        If ctr.Name = sName then
        CType(ctr,RadioButton).Checked = True
        Exit Sub
        Next

        End Sub

        L 1 Reply Last reply
        0
        • S Steve van Niman

          AFAIK? Was able to get to the Checked property by converting the Control to a Radio Button using CType.

          Private Sub ChecktheRadioButton(ByVal sName as String)

          Dim ctr as Control
          For Each ctr in GroupBox2.Controls
          If ctr.Name = sName then
          CType(ctr,RadioButton).Checked = True
          Exit Sub
          Next

          End Sub

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          See, there is no problem whatsoever. Of course it has to be a Control that HAS a Checked property. Now try this:

          CType(GroupBox2.Controls(theNameOfMyTargetRadioButton),RadioButton).PerformClick()

          :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


          S 1 Reply Last reply
          0
          • L Luc Pattyn

            See, there is no problem whatsoever. Of course it has to be a Control that HAS a Checked property. Now try this:

            CType(GroupBox2.Controls(theNameOfMyTargetRadioButton),RadioButton).PerformClick()

            :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


            S Offline
            S Offline
            Steve van Niman
            wrote on last edited by
            #5

            Beautiful. That did the trick. But still a bit confused - what is AFAIK

            L 1 Reply Last reply
            0
            • S Steve van Niman

              Beautiful. That did the trick. But still a bit confused - what is AFAIK

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              FYI[^] :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


              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