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 :)
Printable View
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 :)
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.
If you have VB6, you can create them from scratch like this:
Or if you have VB5, you can load them from a Control Array. Add an OptionButton and set its Index to 0.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
Code:For I = 1 To 100
Load Option1(i)
Option1(i).Move 0, 0
Option1(i).Visible = True
Next I
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
Thank you for answering... it was a great help...