Populating Form Dynamically Via DataColumn Name

I am frequently frustrated with having to drag textbox controls to a form, name them, align them, and bind each one individually to data.

Now, I am trying to do this dynamically. I would like to use the TableLayoutPanel, loop through my dataset, and create the label names and textbox via the DataColumn.ColumnName.

I have the following thus far but am getting the error: "Cannot convert type 'char' to 'System.Data.DataColumn':

oleDbConnection1.Open();
DataSet ds1 = new DataSet();
oleDbDataAdapter1.Fill(ds1);

DataTable dt1;
dt1 = ds1.Tables["paintsys"];

//for each field in ds1, create a label and textbox

int i = 0;

foreach (DataColumn dcCurrent in dt1.Rows.ToString())

{

Label myLabel = new Label();
myLabel.Text = dcCurrent.ColumnName.ToString();
myLabel.Width = 200;
tableLayoutPanel1.Controls.Add(myLabel);

i++;

}

Does anyone have any suggestions or easier solutions?

Thanks,

cj

[1420 byte] By [polymorphicx] at [2007-12-25]
# 1

You need to replace the highlighted line with:

foreach (DataColumn dcCurrent in dt1.Columns)

KarlErickson at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

This seemed to work:

for (int i = 0; i <= dt1.Columns.Count - 1; i++)
{
myLabel.Text = dt1.ColumnsIdea.ColumnName.ToString();

myText.DataBindings.Add("Text", dt1, dt1.ColumnsIdea.ColumnName);

}

polymorphicx at 2007-8-31 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...