How to get the control id

G

Guest

Hi,

I have a form containing 10 checkbox named checkbox1, ... checkbox10. I want
to use one loop to scan these control. Anybody knows how?
Dim i as integer
for i=1 to 10
'Me.checkbox & i.text = "something"
next
Thanks in advance
 
G

Guest

Iterate the form's Controls collection to accomplish your task.

///
Dim ctrl As Object

For Each ctrl In Me.Controls
Console.WriteLine(o)
Next

\\\
 
P

Phill. W

I have a form containing 10 checkbox named checkbox1, ...
checkbox10. I want to use one loop to scan these control.

Use a Control Array.

No, seriously!

Create an array of Controls or, better still, of CheckBoxes, as in

Dim CBList As New CheckBox() { CheckBox1, ... CheckBox10 }

For Each cb As CheckBox in CBList
cb.Text = "something"
Next

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top