I may be going about this the wrong way, so I'll set out the full scenario...
I have a DataTable which holds a number of items - like stock items. The data in this table can change, but it's populated from a database so that it's a distinct list. I want users to be able to select a number of them and I want to do this by creating a new checkBox object for each item in my DataTable.
So far I have the following (which I know is wrong, but illustrates what I'm trying to get at!):
string cbName = "cbNewTest";
int cbPosition = 24;
int cbTab = 1;
foreach (DataRow row in tblAllTests.Rows)
{
string cbNewName = cbName + cbTab.ToString();
this.(cbNewName) = new System.Windows.Forms.CheckBox();
this.testInfoSplitContainer.Panel2.Controls.Add(this.(cbNewName));
this.(cbNewName).AutoSize = true;
this.(cbNewName).Location = new System.Drawing.Point(6, cbPosition);
this.(cbNewName).Name = cbNewName;
this.(cbNewName).Size = new System.Drawing.Size(15, 14);
this.(cbNewName).TabIndex = cbTab;
this.(cbNewName).Text = row["itemDesc"].ToString();
cbPosition = cbPosition + 22;
cbTab = cbTab + 1;
}
So of course the problem is the stuff in the brackets. Essentially, I want this to be whatever is in my string 'cbNewName' but I really don't know how to do this...I'm used to SQL as I'm a database gal, so this probably means I've coded this all wrong...
Any help would be very much appreciated...I'm very new to C# (or for that matter, any programming outside a database) so simple terms would be appreciated!