Results 1 to 5 of 5

Thread: Help with radio buttons, please!

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2

    Question

    Hi everybody! does anyone know how to create dynamic radio buttons? i need to display a list of choices from a database, but i don't know how to determine the number of buttons and assign 'em values during run time.

    Thx all

  2. #2
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    With all respect, forget the "option buttons" (which is the same as radio buttons).

    If you have an "arbitrary" or "unpredictable" number of options, use a list box.

  3. #3
    Guest
    If you have VB6, you can create them from scratch like this:
    Code:
    Private Sub Command1_Click()
    	Controls.Add "VB.OptionButton", "Option1"
    	Me!Option1.Move 0, 0
    	Me!Option1.Caption = Text1
    	Me!Option1.Visible = True
    End Sub
    Or if you have VB5, you can load them from a Control Array. Add an OptionButton and set its Index to 0.
    Code:
    For I = 1 To 100
        Load Option1(i)
        Option1(i).Move 0, 0
        Option1(i).Visible = True
    Next I

  4. #4
    Guest
    I just forgot, you can also use CreateWindowExb.
    Code:
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const WS_CHILD = &H40000000
    Private Const BS_RADIOBUTTON = &H4&
    
    Private Sub Form_Load()
        retval = CreateWindowEx(0, "Button", "Button1", WS_CHILD Or BS_RADIOBUTTON, 32, 32, 64, 64, hwnd, 0, App.hInstance, ByVal 0&)
        ShowWindow retval, 1
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    2

    Talking

    Thank you for answering... it was a great help...

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