How to Populate CheckBoxList from Code

B

Bishop

I'm trying to find out how to populate a CheckBoxList from code without
using a database.

The following code generates 6 unchecked checkboxes without any text.
Dim x As Integer

For x = 0 To 5

Dim myCheckbox As New CheckBox

myCheckbox.Text = "Test " & x

myCheckbox.Checked = True

chkProfiles.Items.Add(myCheckbox)

Next

Any thoughts?
 
Z

zacks

I'm trying to find out how to populate a CheckBoxList from code without
using a database.

The following code generates 6 unchecked checkboxes without any text.
Dim x As Integer

For x = 0 To 5

    Dim myCheckbox As New CheckBox

    myCheckbox.Text = "Test " & x

    myCheckbox.Checked = True

    chkProfiles.Items.Add(myCheckbox)

Next

Any thoughts?

Did you even check the documentation?

CheckBoxList defined:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxlist(vs.85).aspx
 
B

Bishop

No because I could not find any for windows application.

Should have mentioned previously, VB.NET 2005, windows application.

I'm trying to find out how to populate a CheckBoxList from code without
using a database.

The following code generates 6 unchecked checkboxes without any text.
Dim x As Integer

For x = 0 To 5

Dim myCheckbox As New CheckBox

myCheckbox.Text = "Test " & x

myCheckbox.Checked = True

chkProfiles.Items.Add(myCheckbox)

Next

Any thoughts?

Did you even check the documentation?

CheckBoxList defined:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkboxlist(vs.85).aspx
 
K

Kerry Moorman

Bishop,

Isn't the CheckboxList a web control?

For a windows forms application, perhaps you can use the CheckedListBox
control.

Kerry Moorman
 
K

kimiraikkonen

I'm trying to find out how to populate a CheckBoxList from code without
using a database.

The following code generates 6 unchecked checkboxes without any text.
Dim x As Integer

For x = 0 To 5

Dim myCheckbox As New CheckBox

myCheckbox.Text = "Test " & x

myCheckbox.Checked = True

chkProfiles.Items.Add(myCheckbox)

Next

Any thoughts?

Bishop,
If your difficulty is to populate checkedListBox(this control is for
winforms) up to 6 items with text, i hope this is what you want:


' Here chkProfiles is your checkedListbox control
For x As Integer = 0 To 5
chkProfiles.Items.Add("Test" & x)
Next

Thanks,

Onur Güzel
 
B

Bishop

Yes, this is what I was looking for, I didn't realise it was different in
from ASP to Winform. I wanted to add checkbox controls so I could control
text, if it was checked or not, the value (the not seen one), and the color
of the checkbox.



I'm trying to find out how to populate a CheckBoxList from code without
using a database.

The following code generates 6 unchecked checkboxes without any text.
Dim x As Integer

For x = 0 To 5

Dim myCheckbox As New CheckBox

myCheckbox.Text = "Test " & x

myCheckbox.Checked = True

chkProfiles.Items.Add(myCheckbox)

Next

Any thoughts?

Bishop,
If your difficulty is to populate checkedListBox(this control is for
winforms) up to 6 items with text, i hope this is what you want:


' Here chkProfiles is your checkedListbox control
For x As Integer = 0 To 5
chkProfiles.Items.Add("Test" & x)
Next

Thanks,

Onur Güzel
 

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