|
-
July 30th, 2001, 04:50 PM
#1
Dynamically Adding Radio Buttons to a Form During Run-Time > NEED HELP PLS!
I am trying to add radio buttons dynamically at run-time, but am having a couple of problems.
I want to create two option groups. the first is created when the form is loaded. the second group is created when an option from the first group is selected. this works until i select a different option from the first group. the second group won't re-create the new options. Make sense? Any ideas?
Also, I want to be able to set the second group's index property value to a field key in my database (like 40 or 85 depending on the record) when I do this, I get an error for the first option because it doesn't start with 1, when i try to assign a value equal to i - 1 it says the property is read-only. am i doing something wrong?
Any help is greatly appreciated!!
Thanks!
'//this sub works fine, i just included it as a reference for the next sub which is where i am having the problems
private Sub Form_Load()
Dim i as Integer
Dim conn as new ADODB.Connection
Dim rs as new ADODB.Recordset
Dim sql as string
Dim foxpro as string
foxpro = "DB_Tracking"
sql = "SELECT * FROM tbl_supcategory ORDER BY cat_key"
conn.Open foxpro
rs.Open sql, conn, , adLockReadOnly
i = rs.Fields("cat_key")
rs.MoveFirst
While rs.EOF = false
Load optCategory(i)
optCategory(i).Caption = rs.Fields("Category")
optCategory(i).Top = optCategory(i - 1).Top + optCategory(i - 1).Height
optCategory(i).Left = optCategory(i - 1).Left
optCategory(i).Value = false
optCategory(i).Visible = true
i = i + 1
rs.MoveNext
Wend
fraCategory.Height = optCategory(i - 1).Top + optCategory(i - 1).Height + 75
optCategory(0).Visible = false
rs.Close
conn.Close
set rs = nothing
set conn = nothing
End Sub
'//this is where I am having the problems
private Sub optCategory_Click(Index as Integer)
Dim i as Integer
Dim conn as new ADODB.Connection
Dim rs as new ADODB.Recordset
Dim sql as string
Dim foxpro as string
Dim cat_key as string
cat_key = Index
foxpro = "DB_Tracking"
sql = "SELECT * FROM tbl_sup_subcat WHERE cat_key = " & Chr(10) & cat_key & Chr(10) & " ORDER BY sub_key"
conn.Open foxpro
rs.Open sql, conn, , adLockReadOnly
'//if I set i equal to the key in the database, i get error described below
i = rs.Fields("sub_key")
'i = 1
rs.MoveFirst
optSubCategory(0).Index = i - 1
While rs.EOF = false
Load optSubCategory(i)
optSubCategory(i).Caption = rs.Fields("SubCategory")
'//this next line is where i get the error "control array element 'item' doesn't exist"
optSubCategory(i).Top = optSubCategory(i - 1).Top + optSubCategory(i - 1).Height
optSubCategory(i).Left = optSubCategory(i - 1).Left
optSubCategory(i).Value = false
optSubCategory(i).Visible = true
i = i + 1
rs.MoveNext
Wend
optSubCategory(0).Visible = false
rs.Close
conn.Close
set rs = nothing
set conn = nothing
Text1.Text = Index
End Sub
Thanks~
~goddess
[email protected]
"There are no stupid questions, but there are a lot of inquisitive idiots."
-
July 31st, 2001, 12:56 AM
#2
Re: Dynamically Adding Radio Buttons to a Form During Run-Time > NEED HELP PLS!
This line
optSubCategory(0).Index = i - 1
Gives an error, cause the index property of a control is read only. It can only be set at design-time, or dynamically via the Load function, after that, it can't be changed.
Also, when moving on ion the code, you are adressing element i-1. Because you can't set the index, element i-1 probably doesn't exists, resulting in the other error.
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
July 31st, 2001, 08:18 AM
#3
Re: Dynamically Adding Radio Buttons to a Form During Run-Time > NEED HELP PLS!
Thanks for your help with this...I guess I'll just have to have static option buttons since I have to have the index values set to a specific number based on my database.
Thanks again!
Thanks~
~goddess
[email protected]
"There are no stupid questions, but there are a lot of inquisitive idiots."
-
July 31st, 2001, 08:25 AM
#4
Re: Dynamically Adding Radio Buttons to a Form During Run-Time > NEED HELP PLS!
There are some other option though,
why not just set the tag property of the controls to hold the index. This way, when it is clicked, you can refer to it's tag to get the index to the record in the database.
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|