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. C#
  4. Create a grid of radiobutton on the fly

Create a grid of radiobutton on the fly

Scheduled Pinned Locked Moved C#
questioncsshelp
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.
  • D Offline
    D Offline
    Desmond Lim
    wrote on last edited by
    #1

    Hi, I have this problem that requires different areas (30x40, 10x40) of radio buttons. How can I do this on the fly? I can't figure out how can I create the radio buttons and add them to the panel using a for loop? I want to name the radio buttons rb_1_1, rb_1_2 or rb11, rb12, etc. I know I have to create the radio button objects -> RadioButton rb_1_1 = new RadioButton() but how would I change the rb_1_1 when it loops again? Thanks. Desmond

    G 1 Reply Last reply
    0
    • D Desmond Lim

      Hi, I have this problem that requires different areas (30x40, 10x40) of radio buttons. How can I do this on the fly? I can't figure out how can I create the radio buttons and add them to the panel using a for loop? I want to name the radio buttons rb_1_1, rb_1_2 or rb11, rb12, etc. I know I have to create the radio button objects -> RadioButton rb_1_1 = new RadioButton() but how would I change the rb_1_1 when it loops again? Thanks. Desmond

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      Desmond Lim, http://msdn2.microsoft.com/en-us/library/system.windows.forms.radiobutton.aspx[^] Regards, Gareth.

      D 1 Reply Last reply
      0
      • G Gareth H

        Desmond Lim, http://msdn2.microsoft.com/en-us/library/system.windows.forms.radiobutton.aspx[^] Regards, Gareth.

        D Offline
        D Offline
        Desmond Lim
        wrote on last edited by
        #3

        Sorry Gareth, that's not want I wanted. I know I can do it that way but what if I have 1000 radio buttons I want to create, RadioButton rb_1_1 = new RadioButton(); RadioButton rb_1_2 = new RadioButton(); and so on for 1000 times. Is there a way to do it programmatically, so that I can just create a for loop and it creates the radio buttons for me? And I need to do this in windows not ASP.net (I can do it in ASP.net). Thanks. Desmond

        G 1 Reply Last reply
        0
        • D Desmond Lim

          Sorry Gareth, that's not want I wanted. I know I can do it that way but what if I have 1000 radio buttons I want to create, RadioButton rb_1_1 = new RadioButton(); RadioButton rb_1_2 = new RadioButton(); and so on for 1000 times. Is there a way to do it programmatically, so that I can just create a for loop and it creates the radio buttons for me? And I need to do this in windows not ASP.net (I can do it in ASP.net). Thanks. Desmond

          G Offline
          G Offline
          Gareth H
          wrote on last edited by
          #4

          Desmond Lim, Just do:

          for (int i = 0; i < 1000; i++)
          {
          //create controls
          }

          Why do you want to create 1000 radio buttons? Can you give a bit more info on what your trying to do because there might be a better way around it. Regards, Gareth.

          D 1 Reply Last reply
          0
          • G Gareth H

            Desmond Lim, Just do:

            for (int i = 0; i < 1000; i++)
            {
            //create controls
            }

            Why do you want to create 1000 radio buttons? Can you give a bit more info on what your trying to do because there might be a better way around it. Regards, Gareth.

            D Offline
            D Offline
            Desmond Lim
            wrote on last edited by
            #5

            I'm creating a software that allows the user to enter data for research purposes. The slide/grid they use comes in different sizes, 20x30, 40x40, 100x30, etc. They want to be able to choose the size (by list box) and when a particular size is chosen, the grid of radio buttons corresponding to the size that they want will be created i.e. if they choose 20x30, 20 columns by 30 rows of radio buttons will be created. The radio buttons will then be use to enter the data that corresponds to that part of the grid, that is to say, when the user clicks the Col 2 and Row 3 radio button, a window might pop up with the information needed for that part. Which means that each individual radio button has to be identifiable. So back to my question how do you do a create radio button with different IDs because I know that when you do a RadioButton rb01 = new RadioButton(); it creates the radio button object, I just don't know how to create radio buttons that have different IDs, i.e. rb01, rb02, rb03, etc. via using a loop. I know that if I do something like for (int i = 0; i < 1000; i++) { RadioButton rbNew = new RadioButton(); (move rbNew to a particular x y coordinate); rbNew.name = "rb01"; } This doesn't seem to work for I only get 1 radio button. If you can think another way to do this, I'll really appreciate it. Thanks. Desmond

            G 1 Reply Last reply
            0
            • D Desmond Lim

              I'm creating a software that allows the user to enter data for research purposes. The slide/grid they use comes in different sizes, 20x30, 40x40, 100x30, etc. They want to be able to choose the size (by list box) and when a particular size is chosen, the grid of radio buttons corresponding to the size that they want will be created i.e. if they choose 20x30, 20 columns by 30 rows of radio buttons will be created. The radio buttons will then be use to enter the data that corresponds to that part of the grid, that is to say, when the user clicks the Col 2 and Row 3 radio button, a window might pop up with the information needed for that part. Which means that each individual radio button has to be identifiable. So back to my question how do you do a create radio button with different IDs because I know that when you do a RadioButton rb01 = new RadioButton(); it creates the radio button object, I just don't know how to create radio buttons that have different IDs, i.e. rb01, rb02, rb03, etc. via using a loop. I know that if I do something like for (int i = 0; i < 1000; i++) { RadioButton rbNew = new RadioButton(); (move rbNew to a particular x y coordinate); rbNew.name = "rb01"; } This doesn't seem to work for I only get 1 radio button. If you can think another way to do this, I'll really appreciate it. Thanks. Desmond

              G Offline
              G Offline
              Gareth H
              wrote on last edited by
              #6

              Desmond Lim,

              rbNew.name = "rb" + i.ToString();

              Regards, Gareth.

              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