Hi,
Needs ome advice on what is probably, a no brainer question however its beeing driving me round in circles.
I have created a simple WinForms application in VS.NET 2005 that loads a database table during runtime, and then based on some rules, proceeds to dynamically create controls on the form based on the data it finds in the table.
However I am having trouble working out how to loop through the dataset and then based on the total number of rows, create 'n' number of labels that have their Text property filled by the data found in a particular column e.g:
As per above, I got most of what I wanted working but got a little stuck when I needed to dynamically create a new Label each time. As this is being done during runtime I need the code to do the following:
1. Start Loop
2. Create a new instance of the Label Control
3. Work with this Control (properties etc)
4. Add this Control to the WinForm
5. Next Loop
6. Create the next new instane of the label Control
..
..
etc
Thanks in advance,
Fz
Needs ome advice on what is probably, a no brainer question however its beeing driving me round in circles.
I have created a simple WinForms application in VS.NET 2005 that loads a database table during runtime, and then based on some rules, proceeds to dynamically create controls on the form based on the data it finds in the table.
However I am having trouble working out how to loop through the dataset and then based on the total number of rows, create 'n' number of labels that have their Text property filled by the data found in a particular column e.g:
Code:
for (i = 0; i <= RowCount - 1; i++)
{
Label Label = new Label(); //create a new label each time we hit a new row.. this bit is not working yet :s
// set the location of the control, move it down the Y axis each time we loop
Label.Location = new Point(12, YPos);
// populate the text property for the label
Label.Text = this.DataSet1.Table1.Rows[i]["Column Name"].ToString();
YPos = YPos + 12; // set the new Y scale value
this.Controls.Add(Label); // add the new control to the form
}
As per above, I got most of what I wanted working but got a little stuck when I needed to dynamically create a new Label each time. As this is being done during runtime I need the code to do the following:
1. Start Loop
2. Create a new instance of the Label Control
3. Work with this Control (properties etc)
4. Add this Control to the WinForm
5. Next Loop
6. Create the next new instane of the label Control
..
..
etc
Thanks in advance,
Fz