concatenate integer variable

  • Thread starter Thread starter tirrell payton
  • Start date Start date
T

tirrell payton

Hello all,

I have a question about the concatenation operator in C#. For example, I
want to concatenate an integer variable to a control.

I have an integer, i. I have checkboxes, checkbox0 - checkbox5.
As I loop through my integers i - 5, I want to check my checkboxes,
checkbox0- checkbox5.

for (int i = 0; i < 5; i++)

{

checkbox+i+.checked = true;

}



However, referring to the checkboxes in the for loop as checkbox+i+.checked
= true is not working. Any help would be appreciated regarding
concatenating the checkbox control with the integer value.

-Tirrell
 
Hi,

I assume that you are using winforms
If you have fixed set of controls - as in the example, you can write

checkbox1.checked = true;
checkbox2.checked = true;
checkbox3.checked = true;
.....

In such case, there is no need to write a loop.


HTH
Kalpesh
 
Hi,
You could use the checked changed event of each box to set an Array value
then just traverse the array.
private void checkBox1_CheckedChanged(object sender, EventArgs e)

{

//Code here to set Array member true if checked else false

}

HTH

Bob
 
tirrell payton said:
Hello all,

I have a question about the concatenation operator in C#. For example, I
want to concatenate an integer variable to a control.

I have an integer, i. I have checkboxes, checkbox0 - checkbox5.
As I loop through my integers i - 5, I want to check my checkboxes,
checkbox0- checkbox5.

for (int i = 0; i < 5; i++)

{

checkbox+i+.checked = true;

}

However, referring to the checkboxes in the for loop as
checkbox+i+.checked = true is not working. Any help would be appreciated
regarding concatenating the checkbox control with the integer value.

C# can't do exactly what your asking - thank goodness.

What you want is an array (or other container) of controls.
For example:

for (int i = 0; i < 5; i++)
{
checkboxes.checked = true;
}

Try Googling "C# arrays" and "C# collections" for starters...

m
 

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

Back
Top