How do I repeat Controls like a repeat region in ASP

  • Thread starter Thread starter Daren Hawes
  • Start date Start date
D

Daren Hawes

Hi,

I am planning an VB.NET Windows Application that is a survey system.

I need to know how to "Repeat" questions etc.

In asp I would create a table, bind the data to controls and then repeat
the table for the number of questions..

--------------------------------------
|Question 1: | <-- Repeat Region
---------------------------------------
|Question 2 etc.. |
---------------------------------------

and so on

But how can I do this in VB.NET Win Forms?

My questions are..

1. How do I manage the location of the labels, textboxes etc. As
eveything is exact placement, where as in ASP the next table simply fell
under the last...simple.

2. Do I use Crystal Reports?

3. Do you see what I mean.

My questions are totally placement of the data 1 on top of the other...

If you understand, please help!

Thx
 
Daren,
I've done something like this before. It sounds like you want to add
controls dynamically to a winform with a question format. What I did was
start at a certain x/y coordinate on the form by using a Point structure and
assigning it to the Location property of the labels/textboxes. All this
logic was wrapped in a loop that went through all my questions and answer
types. Here is a quick example. I wrote this really quick just so you can
see a real rough example of how to add controls dynamically to a form. The
example adds 10 rows to the form.

private void Form1_Load(object sender, System.EventArgs e)
{
Label lblNumber = null;
Label lblQuestion = null;
int yCooridinate = 10;

for(int index = 1;index <=10;index++)
{
lblNumber = new Label();
lblNumber.Text = index.ToString() + ")";
lblNumber.AutoSize = true;
lblNumber.Location = new Point(10,yCooridinate);

lblQuestion = new Label();
lblQuestion.Text = "Question # " + index.ToString();
lblQuestion.AutoSize = true;
lblQuestion.Location = new Point(30,yCooridinate);

yCooridinate+=20;

this.Controls.AddRange(new Control[2]{lblNumber,lblQuestion});
}
}

HTH
 
Back
Top