When adding usercontrol dynamically on the form i got a right ouput
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select LastName from Employee", myDatabaseConnection))
using (SqlDataAdapter da = new SqlDataAdapter(SqlCommand))
{
SqlDataReader DR1 = SqlCommand.ExecuteReader();
int y = 0;
while (DR1.Read())
{
y++;
for (int i = 0; i < y; i++)
{
UserControl2 userconrol = new UserControl2();
userconrol.Location = new Point(50, 30 * i);
userconrol.Tag = i;
userconrol.LastName = (string)DR1["LastName"];
this.Controls.Add(userconrol);
}
}
}
}
But when i use flowlayoutpanel to add controls dynamically this is what happened:
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select LastName from Employee", myDatabaseConnection))
using (SqlDataAdapter da = new SqlDataAdapter(SqlCommand))
{
SqlDataReader DR1 = SqlCommand.ExecuteReader();
int y = 0;
while (DR1.Read())
{
y++;
for (int i = 0; i < y; i++)
{
UserControl2 userconrol = new UserControl2();
userconrol.Tag = i;
userconrol.LastName = (string)DR1["LastName"];
flowLayoutPanel1.Controls.Add(userconrol);
}
}
}
}
What is the problem ? I use the same loop why is it when i use flowlayoutpanel to add control dynamically it doesn't show the same output?