|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamically created checkboxes within a panel - how do i get the value?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 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 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 > 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. -- Show quoteHide quoteTerry "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 > > > > > 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 > > 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 >> > >
Reading one record from an Access DB
Inherited form problem Function 'GetData' doesn't return a value on all code paths... dataser design considerations converting short to unicode without System.Text.UnicodeEncoding ?Delegates and Interaces - similarities/differences? How to find files in a directory Can I write and read a STRUCTURE to a file or to a Database??? Image access problem Balloontip - tooltip add link |
|||||||||||||||||||||||