Question
October 16, 2010 at 10:32 AM
martinbullock15

VB.NET Loop through Checkbox to select Text

by martinbullock15 . Updated 15 years, 10 months ago

Hi

I am stuck on a piece of code i am trying to complete.

I have a series of checkboxes that i want to loop through to check if Checked and if so output the Text which is in the Corresponding TextBox next to the Checkbox.

I have the following code which loops through the checkboxes i have grouped together and at the minute it just counts if it is checked, but instead i would like to get the Text in the Textbox.

The Text Box and the Checkbox will have the same name e.g.

chkA – txtA
chkB – txtB
chkC – txtC

Dim AllCheckBoxes As CheckBox() = {CheckBox1, CheckBox2, CheckBox3, CheckBox4}
Dim varCheckCount As Integer

Dim Chk As CheckBox

For Each Chk In AllCheckBoxes

If Chk.CheckState = 1 Then

varCheckCount = varCheckCount + 1

End If

Next

txtChecked.Text = varCheckCount

Any suggestions on how or even if this can be done would be very grateful.

Kind Regards

This discussion is locked

All Comments