Good day all.
I am currently working on a little side project where I want to create a database via a windows forms application.
I have managed to create the database fine from the application, my problem comes in when I need to create the tables.
On the application I dynamically create text boxes (on link label click events) for the table name and column names. This part works fine, I create each text box with a unique name in an attempt to create a bit more clarity when it comes to creating the tables with their columns.
My problem comes in when I need to select all the column text boxes for the table i need to create.
I have found some code(as in the create_click) that I tried to see if i could do this, but it ends up only recognizing the last table text box added and not any of the others.
Now my question is. Is there any way for me to be able to do this or do I need to totally rethink my approach to this?
I am aware that the table insert code is not done yet, that is not my problem, I just simply want the text from the Column text boxes to be linked under each Table text box.
Its hard to explain exactly what I need to do I know, but if you need any more clarification on this please ask.
My code as to what I have done so far is below.(This is the entire form code so you can copy and reproduce the application for testing)
I thank you in advance and sorry for the long post.
private void AddColumn_Click(object sender, EventArgs e)
{
if (i == 0)
{
i = 1;
}
lblColumns = new Label();
Column = new TextBox();
Types = new TextBox();
nulls = new CheckBox();
notnulls = new CheckBox();
lblColumns.Text = "Column " + i;
lblColumns.Location = new Point(345, Table.Bottom + (i * 25));
lblColumns.AutoSize = true;
Column.Location = new Point(lblColumns.Location.X + 60, lblColumns.Location.Y);
Column.Size = Columns.Size;
Column.Name = Table.Name + Column.Name + "Coulmn" + i;
Types.Location = new Point(Type.Location.X, Column.Location.Y);
Types.Size = Type.Size;
Types.Name = "Type" + i;
nulls.Text = "NULL";
nulls.Location = new Point(Null.Location.X, Column.Location.Y);
nulls.AutoSize = true;
nulls.Checked = false;
nulls.Name = "nulls" + i;
notnulls.Text = "NOT NULL";
notnulls.Location = new Point(NotNull.Location.X, Column.Location.Y);
notnulls.AutoSize = true;
notnulls.Checked = true;
notnulls.Name = "notnulls" + 1;
CheckBox IDEN = new CheckBox();
IDEN.Text = "IDEN";
IDEN.Name = "IDEN" + i;
IDEN.Location = new Point(Types.Location.X - 60, Types.Location.Y);
IDEN.AutoSize = true;
IDEN.Checked = false;
this.Controls.Add(IDEN);
this.Controls.Add(nulls);
this.Controls.Add(notnulls);
this.Controls.Add(lblColumns);
this.Controls.Add(Column);
this.Controls.Add(Types);
if (i == 1)
{
IDEN.Checked = true;
}
i++;
AddTable.Visible = true;
AddTable.Location = new Point(Tables.Location.X + 154, Column.Location.Y);
AddColumn.Location = new Point(Columns.Location.X + (Column.Width / 3), Column.Bottom + 5);
Create.Visible = true;
Create.Location = new Point(this.Width / 2 - Create.Width / 2, AddColumn.Bottom + 20);
this.AutoScrollPosition = new Point(Math.Abs(this.AutoScrollPosition.X), this.VerticalScroll.Maximum);
}
private void AddTable_Click(object sender, EventArgs e)
{
lblTables = new Label();
Table = new TextBox();
Table.Name = Table.Name + "Table" + j.ToString();
lblTables.Text = "Table " + j;
Table.Size = Tables.Size;
if (i == 1)
{
lblTables.Location = new Point(10, Columns.Bottom + (j * 25));
Table.Location = new Point(lblTables.Location.X + 60, lblTables.Location.Y);
}
if (i > 1)
{
lblTables.Location = new Point(10, Column.Bottom + (j * 25));
Table.Location = new Point(lblTables.Location.X + 60, Column.Bottom + (j * 25));
AddColumn.Location = new Point(Columns.Location.X + 154, Table.Location.Y);
}
this.Controls.Add(Table);
this.Controls.Add(lblTables);
i = 0;
j++;
AddColumn.Visible = true;
AddTable.Visible = false;
Create.Visible = false;
this.AutoScrollPosition = new Point(Math.Abs(this.AutoScrollPosition.X), this.VerticalScroll.Maximum);
}
private void Create_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.Name.Contains(Table.Name))
{
MessageBox.Show(ctrl.Name);
}
}
}