Re: Creating variables in a loop!



Mark, thanks for the response, I appreciate it.

It appears to work, the only thing I'm a little bit confused on is how
I retrieve the information (the boolean checked or not checked) back
from the variable if the variable is in fact the same for each one?

Any hints on how I might be able to retrieve the boolean state of each
of them after the grid / table has already been built?

Thanks!!!

Todd

You added the checkboxes to tablecells, that were added to a tablerow.
You can retrieve them the same way: loop through the Cells collection
of the row, and find the first (only) control inside that cell.
It's "just" a Control, so you will have to cast it to a CheckBox.

Hans Kesting


"Mark Fitzpatrick" wrote:

No. It also wouldn't do much good as a variable is only alive for the
scope of the loop and doesn't exist outside it. Keep in mind, you are
creating an object here, specifically object inherited from a
webcontrol object. That means you have a property available to you
that you can set the ID of the resultant control. The tmCell.ID
property would allow you to set the name of the control. You may also
want to set the AccessKey property as well. Try playing with this
concept a bit as even if you could alter the name of the variable in
the loop, it doesn't do you any good as that reference is useless the
second you iterate through the loop again, or after the loop
completes.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Todd Jaspers" <ToddJaspers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:A6D24909-8BE9-4AF3-916E-F12B938AD29A@xxxxxxxxxxxxxxxx

Hey guys,

Is there ANY way to accomplish this: (see below)? Basically, I want
to
have a loop (a < 3 is just for testing purposes, it will be an
underermined
amount). In this loop, I want to be able to create a new cell each
time.
In
this cell, I want the variable name to change. Is this at ALL
possible?
I've
never been able to figure this out in some of the other languages.
Any help would GREATLY be appreciated.

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell = new TableCell();
tmRow.Cells.Add(tmCell);
CheckBox chk = new CheckBox();
chk.Text = "This is a test for #" + a;
tmCell.Controls.Add(chk);
tmRow.Cells.Add(tmCell);
a++;
}
would it be something like this???

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell#a# = new TableCell();
tmRow.Cells.Add(tmCell#a#);
CheckBox chk#a# = new CheckBox();
chk#a#.Text = "This is a test for #" + a;
tmCell#a#.Controls.Add(chk);
tmRow#a#.Cells.Add(tmCell#a#);
a++;
}
Thanks!!!



.



Relevant Pages

  • Re: How to capture Mouse clicks and Keystrokes in a VB app
    ... The text should then be visible inside the cell. ... I think you want a textbox. ... a nested for loop would work: ... Just use a textbox and let the control hold on to the text. ...
    (microsoft.public.dotnet.languages.vb)
  • Delay when writing cell information to Excel from VBA Macro
    ... When I loop through in VBA setting a value for a variable the loop goes ... second delay between each cell. ... any way to control this wait? ...
    (microsoft.public.excel.programming)
  • Get controls absolute/screen left/top?
    ... how can i retrieve the screen position of a control on a form? ... control that can be embedded an infinite number of levels ... i suppose i can always loop through the ...
    (microsoft.public.dotnet.languages.vb)
  • Problems Defining Object Variable in For Each Loop
    ... Normally I would build the loop as follows: ... For each cell in Worksheet ... expecting to see the same sheet name. ...
    (microsoft.public.excel.programming)
  • benchmark on rewrited pde1.frt
    ... Benchmarks for example exposed in pde1.frt(rectangular domenium) by ... LOOP structure -> the word ... CREATE SUBDOM #SUBDOM 2* CELLS ALLOT ... CELL +LOOP ...
    (comp.lang.forth)