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

