|
-
Aug 2nd, 2000, 02:18 AM
#1
Thread Starter
New Member
hello,
can anybody please help me out with this
I want to create control at runtime when the form is been loaded .the control should be a check box and the number of controls generated should be depending up on the number of records in the database . And the caption property should also be taken from the table, field name (desc).
Can this thing be posible Please help me out with this
-
Aug 2nd, 2000, 03:14 AM
#2
Lively Member
you can create a control array and use
load controlname(index)
to load a new control
YC Sim
Teenage Programmer
UIN 37903254
-
Aug 2nd, 2000, 04:31 AM
#3
Thread Starter
New Member
could u pl give me the code
-
Aug 2nd, 2000, 06:18 AM
#4
Well ....
With VB6 you can directly 'Add' controls to a form at runtime. The code for your problem would look like this:
Code:
Private Sub LoadControls()
Dim WithEvents newCheck As CheckBox
Dim rs1 As RecordSet
Dim I As Integer
Set rs1 = db1.OpenRecordSet("Select * from <table name>")
for I = 0 to rs1.Fields.Count -1 Step 1
Set newCheck = Me.Controls.Add("VB.CheckBox","Check" & CStr(I))
newCheck.Caption = rs1.Fields(I).Name
newCheck.Value = rs1.Fields(I).Value
newCheck.Visible = True
Next
End Sub
The only hitch in the above code is I have not provided for a proper display of all checkboxes. Add the code which displays each checkbox at a different location.
-
Aug 2nd, 2000, 07:40 AM
#5
_______
<?>
I've seen the post similar to this one some time ago. In the answer below the user decided to use a listview to display the names in checkboxes...perhaps it might help or at least you can trace this guys questions and perhaps find your answer in his questions.
http://forums.vb-world.net/showthrea...threadid=21669
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 2nd, 2000, 08:15 AM
#6
Try:
Code:
Private Sub Form_Load()
Controls.Add "VB.CheckBox", "Check1"
Me!Check1.Caption = "CheckBox"
Me!Check1.Move 0, 0
Me!Check1.Visible = True
End Sub
-
Aug 2nd, 2000, 03:41 PM
#7
Dynamic Guru!
Well, Megatron, searching for dynamic addition of controls? Is it pure coincidence that both your posts have corrected my code?
Well, I must say that that's why a Guru is different from a Lively Member, my own very code, but so short and sweet!
Thanks a lot Guru!!
-
Aug 2nd, 2000, 03:52 PM
#8
transcendental analytic
HA! can you get shorter than this?
Nope, but you could probably go for ycsim's sample, a bit more dynamically with
Code:
load controlname(controlname.count)
And it works in VB5 too
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 2nd, 2000, 03:59 PM
#9
honeybee: No problem.
Kedaman: Some might argue about that because you are actually loading it from a Control Array, hence, you would need at least 1 instance of it on the Form.
-
Aug 2nd, 2000, 04:25 PM
#10
transcendental analytic
Well, both you and i have to is that way anyway, since we have vb5, so i'm not arguing.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 3rd, 2000, 09:08 PM
#11
On second thoughts....
Just after posting the above reply, Megatron, I was thinking about your solution, and I think it is very close to useless.
Your code does not allow me to add a number of controls using a loop, whereas mine does.
Please allow me to withdraw my earlier comment.
-
Aug 7th, 2000, 06:27 AM
#12
Frenzied Member
I'm goanna have to defend megatron here in that your solution was correct and didn't need adding to, wheeas Megs, although not that useful in the context of the question is very useful for other things, I didn't know you could do It like that, and now I do. If he'd either not posted, or posted the same reply as you, nobody would have learned anything
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
|