Simple loop question - code check

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hi

I have five check boxes in a windows form. They are called chkEQUDS01,
chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text
name for the check boxes from a datatable and have wrote the code below:

If dtEq.Rows(0).Item(2) = 1 Then
chkEQUDS01.Enabled = True
chkEQUDS01.Text = dtEq.Rows(0).Item(1)
End If

If dtEq.Rows(1).Item(2) = 1 Then
chkEQUDS02.Enabled = True
chkEQUDS02.Text = dtEq.Rows(1).Item(1)
End If
If dtEq.Rows(2).Item(2) = 1 Then
chkEQUDS03.Enabled = True
chkEQUDS03.Text = dtEq.Rows(2).Item(1)
End If
If dtEq.Rows(3).Item(2) = 1 Then
chkEQUDS04.Enabled = True
chkEQUDS04.Text = dtEq.Rows(3).Item(1)
End If
If dtEq.Rows(4).Item(2) = 1 Then
chkEQUDS05.Enabled = True
chkEQUDS05.Text = dtEq.Rows(4).Item(1)
End If
If dtEq.Rows(5).Item(2) = 1 Then
chkEQUDS06.Enabled = True
chkEQUDS06.Text = dtEq.Rows(5).Item(1)
End If

Can anyone tell me if there is a better way to write this? In particular,
how could I create an integer and then refer to a name and the integer which
make up the chkbox name, for example, chkEQUDi and as you password round
each loop i would increase by 1.

Hope this makes some sense?

Thanks
Rich
 
Heh, I was kinda avoiding this one. There is a CheckBox control array
already included in the DotNetFramework if you look at your Toolbox.

Just go to Add Components, and you'll see it in there. I think its in the
Microsoft.VisualBasic namespace.

-CJ
 
Rich said:
I have five check boxes in a windows form. They are called
chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am
getting the text name for the check boxes from a datatable and have
wrote the code below:

Can anyone tell me if there is a better way to write this? In
particular, how could I create an integer and then refer to a name
and the integer which make up the chkbox name, for example, chkEQUDi
and as you password round each loop i would increase by 1.

Hope this makes some sense?

Add the controls to an array declared as a Form field:

Private m_chkEQUDS As Checkbox()
'...
m_chkEQUDS = new checkbox() _
{chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, _
chkEQUDS05, chkEQUDS06}

Now you can use a loop on the array.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top