private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
//tablename
string tableName = e.Item.SubItems[1].Text;
//get a the names of the attributes of the selected table in listview1 into a table
DataTable dat = new Connectoperations().describeTable(tableName);
//a loop to attributes in the table into the listview
dataGridView1.Rows.Clear();
int i = 0;
foreach (DataRow row in dat.Rows)
{
dataGridView1.Rows.Add(row[0]);
for (int j = 0; j < 6; j++)
{
dataGridView1[j, i].Value = row[j].ToString();
}
if (tableControls.Count < 1)
{
//setting the default of the suggested control to textbox
dataGridView1[6, i].Value = "TextBox";
}
else
{
dataGridView1[6, i].Value = "TextBox";
//load control settings stored earlier
for (int a = 0; a < tableControls.Count; a++)
{
//the table names match
if (tableControls[a].tablename == tableName)
{
//load appropriate controlGUYYYYYYYYYYYYYYYYYYYYYY
try
{
dataGridView1[6, i].Value = tableControls[a].controls[i];
}
catch
{
}
}
}
}
i++;
}
listView1.Items[seleteclistviewindex].BackColor = Color.White;
seleteclistviewindex = e.ItemIndex;
listView1.Items[seleteclistviewindex].BackColor = Color.Orange;
myproject.selectedTable = e.Item.SubItems[1].Text;
//load relations
for (int y = 0; y < relations.Count; y++)
{
if (relations[y].name == tableName)
{
int counter = 1;
//load has many
listView3.Items.Clear();
for (int x = 0; x < relations[y].has.Count; x++)
{
ListViewItem lvi = new ListViewItem(counter.ToString());
lvi.SubItems.Add(relations[y].has[x]);
listView3.Items.Add(lvi);
counter++;
}
//load belong to
listView4.Items.Clear();
counter = 1;
for (int x = 0; x < relations[y].belongsTo.Count; x++)
{
ListViewItem lvi = new ListViewItem(counter.ToString());
lvi.SubItems.Add(relations[y].belongsTo[x]);
listView4.Items.Add(lvi);
counter++;
}
}
}
}