By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,548 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,548 IT Pros & Developers. It's quick & easy.

Dynamically created checkboxes within a panel - how do i get the value?

P: n/a
I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)
NewCheckbox.AutoSize = True
NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0)
NewCheckbox.Name = "Checkbox" & counter1 + 1

the problem I have is how do i access the value of that checkbox? (usually
it would be just checkbox1.checked, but obvioulsy this does not work)

Thanks

Mike Fellows
Jul 13 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a

use a for loop
and before this name ur controls prperly.
Asad

Mike Fellows wrote:
I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)
NewCheckbox.AutoSize = True
NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0)
NewCheckbox.Name = "Checkbox" & counter1 + 1

the problem I have is how do i access the value of that checkbox? (usually
it would be just checkbox1.checked, but obvioulsy this does not work)

Thanks

Mike Fellows
Jul 13 '06 #2

P: n/a
maybe you should read before posting

and atleast attempt to spell correctly

the checkbox names i gave where an example

and the for loop is fairly obvious, but again that was not my question!


<as********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>
use a for loop
and before this name ur controls prperly.
Asad

Mike Fellows wrote:
>I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)
NewCheckbox.AutoSize = True
NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0)
NewCheckbox.Name = "Checkbox" & counter1 + 1

the problem I have is how do i access the value of that checkbox?
(usually
it would be just checkbox1.checked, but obvioulsy this does not work)

Thanks

Mike Fellows

Jul 13 '06 #3

P: n/a
Hi Mike,
Are the checkboxes the only controls in the panel? If so, then the
panels control collection would be 1-1 wth the checkboxes. ie CheckBox0 <=>
Me.Panel2.Controls(0). If not, why not keep a seperate collection of
references to the checkboxes you add and reference the correct one via the
index of the collection.
--
Terry
"Mike Fellows" wrote:
maybe you should read before posting

and atleast attempt to spell correctly

the checkbox names i gave where an example

and the for loop is fairly obvious, but again that was not my question!


<as********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...

use a for loop
and before this name ur controls prperly.
Asad

Mike Fellows wrote:
I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)
NewCheckbox.AutoSize = True
NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0)
NewCheckbox.Name = "Checkbox" & counter1 + 1

the problem I have is how do i access the value of that checkbox?
(usually
it would be just checkbox1.checked, but obvioulsy this does not work)

Thanks

Mike Fellows


Jul 13 '06 #4

P: n/a
I think you are confusing the name of the checkbox and the reference to
the checkbox, you cannot just use the name of the checkbox to access
it's members as you suggest. Instead, you need the reference to the
checkbox.

So Asad was basically correct.

Dim cbx As checkbox
'Get a reference to the cbx named checkbox1 within panel1
For c as control in panel1.controls
If typeof(c) is checkbox then
cbx = c
If cbx.Name = "checkbox1" then
Exit For
Else
cbx = Nothing
End If
End If
Next

If Not cbx Is Nothing Then
If cbx.Checked then
'checkbox named checkbox1 is checked so do whatever here.
End if
End If

Andy

Mike Fellows wrote:
maybe you should read before posting

and atleast attempt to spell correctly

the checkbox names i gave where an example

and the for loop is fairly obvious, but again that was not my question!


<as********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...

use a for loop
and before this name ur controls prperly.
Asad

Mike Fellows wrote:
I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)
NewCheckbox.AutoSize = True
NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0)
NewCheckbox.Name = "Checkbox" & counter1 + 1

the problem I have is how do i access the value of that checkbox?
(usually
it would be just checkbox1.checked, but obvioulsy this does not work)

Thanks

Mike Fellows
Jul 13 '06 #5

P: n/a
Thanks

I understood i couldnt just use.checked but wasnt sure how else to do it

Thanks

Mike Fellows
"CaffieneRush" <Ca**********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
>I think you are confusing the name of the checkbox and the reference to
the checkbox, you cannot just use the name of the checkbox to access
it's members as you suggest. Instead, you need the reference to the
checkbox.

So Asad was basically correct.

Dim cbx As checkbox
'Get a reference to the cbx named checkbox1 within panel1
For c as control in panel1.controls
If typeof(c) is checkbox then
cbx = c
If cbx.Name = "checkbox1" then
Exit For
Else
cbx = Nothing
End If
End If
Next

If Not cbx Is Nothing Then
If cbx.Checked then
'checkbox named checkbox1 is checked so do whatever here.
End if
End If

Andy

Mike Fellows wrote:
>maybe you should read before posting

and atleast attempt to spell correctly

the checkbox names i gave where an example

and the for loop is fairly obvious, but again that was not my question!


<as********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googleg roups.com...
>
use a for loop
and before this name ur controls prperly.
Asad

Mike Fellows wrote:
I have created some checkboxes within a panel using the code below
Dim NewCheckbox As New CheckBox
Me.Panel2.Controls.Add(NewCheckbox)
NewCheckbox.Location = New Point(XLocation, YLocation)
NewCheckbox.AutoSize = True
NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0)
NewCheckbox.Name = "Checkbox" & counter1 + 1

the problem I have is how do i access the value of that checkbox?
(usually
it would be just checkbox1.checked, but obvioulsy this does not work)

Thanks

Mike Fellows

Jul 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.