Hi, this is my first post, so any help or advicing is welcome.
I have a form in which i want to show records from a database and create buttons for each record, the problem is that i need to point the buttons in diferent locations inside the form based in the last button position, this is my starting code:
MySqlCommand comm = new MySqlCommand("SELECT * FROM sah_rooms WHERE hotel_id = 1 ", clsMySQL.con);
try
{
MySqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
foreach (var element in reader)
{
btnAdd.Size = new System.Drawing.Size(150, 90);
if (reader["maintenance"].ToString() == "1")
{
btnAdd.BackColor = Color.CadetBlue;
}
else if (reader["maintenance"].ToString() == "0")
{
btnAdd.BackColor = Color.BlueViolet;
}
btnAdd.Text = reader["name"].ToString();
btnAdd.Location = new Point(30, btnAdd.Bottom + 30);
MessageBox.Show(reader["name"].ToString());
panelEx1.Controls.Add(btnAdd);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
This code only shows one button or all the buttons placed one over one.
Thanks!