Home All Groups Group Topic Archive Search About

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

Author
13 Jul 2006 11:15 AM
Mike Fellows
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

Author
13 Jul 2006 12:09 PM
asad.naeem
use a for loop
and before this name ur controls prperly.
Asad

Mike Fellows wrote:
Show quoteHide quote
> 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
Author
13 Jul 2006 12:35 PM
Mike Fellows
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!




<asad.na***@gmail.com> wrote in message
Show quoteHide quote
news:1152792596.747009.188770@m79g2000cwm.googlegroups.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
>
Author
13 Jul 2006 1:56 PM
Terry
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


Show quoteHide quote
"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!
>
>
>
>
> <asad.na***@gmail.com> wrote in message
> news:1152792596.747009.188770@m79g2000cwm.googlegroups.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
> >
>
>
>
Author
13 Jul 2006 6:29 PM
CaffieneRush
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:
Show quoteHide quote
> 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!
>
>
>
>
> <asad.na***@gmail.com> wrote in message
> news:1152792596.747009.188770@m79g2000cwm.googlegroups.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
> >
Author
14 Jul 2006 7:50 AM
Mike Fellows
Thanks

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

Thanks

Mike Fellows


Show quoteHide quote
"CaffieneRush" <CaffieneR***@gmail.com> wrote in message
news:1152815353.850206.13150@m73g2000cwd.googlegroups.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!
>>
>>
>>
>>
>> <asad.na***@gmail.com> wrote in message
>> news:1152792596.747009.188770@m79g2000cwm.googlegroups.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
>> >
>