CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2001
    Posts
    5

    Radio Buttons at run time

    Hi

    Am developing a project in VB, want to know if there is a way by which i can create radio buttons at run time. All i want to do is querry a database and depending on the records want to create radio buttons equal to the number of records returned by my querry.

    How do I do that? An early reply/suggestion would really help

    Thanks


  2. #2
    Join Date
    Jul 2000
    Location
    The Netherlands
    Posts
    26

    Re: Radio Buttons at run time

    What you need to do is place a single radio button on the form, and then set it's index property to 0. During runtime you can then use the Load() function to load any other index of that radio button. Then you can set it's top and left properties to distinct it from the original button. Similar, using the Unload() function, you can remove the radio button indexes you no longer need. For example:
    private Sub DoThing()
    for x = 1 to NumberOfRecords
    Load MyRadioButton(x)
    next x
    End Sub


    I hope my information was useful!


  3. #3
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Radio Buttons at run time

    Hi,
    You can use the "Load" function to dynamically create a control at run time.

    Firstly, let's create a model radio button control in the layout of the form, set the index=0, and visable=False. The actually radio button arrays will be created as following:
    ======
    i=1
    rs.MoveFirst

    While rs.EOF=False

    Load Option1(i)
    Option1(i).Caption = rs!YourField
    Option1(i).Top = Option1(i - 1).Top + Option1(i - 1).Height
    Option1(i).Left = Option1(i - 1).Left
    Option1(i).Value = False 'You can decide if it should be selected
    'Make sure the just created radio button to be visible
    Option1(i).Visible = True

    i=i+1
    rs.MoveNext

    Wend

    =======

    Hope this helps.


    Regards,

    Michi
    MCSE, MCDBA

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

Featured