I am working on a prototype project in c# WinForms, that has 3 forms as follows:
1-MasterForm 2-Layout 3-UpdateLayout i also have a table in my database, that table simply have 2 column one for the layout_no, another for layout_status. if the layout is busy i need to change its color to red, if not busy i keep it to green color.
Ny problem after I update the layout to busy is, that it doesn't refresh in the MasterForm.
Here's my code for UpdateLayout Form:
public void refreshLayout()
{
try
{
using (SQLiteConnection con = new SQLiteConnection(ConnectToDB))
{
con.Open();
using (SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT layout_no, is_busy FROM layout_table", con))
{
DataTable dt = new DataTable();
da.Fill(dt);
int totalrows = dt.Rows.Count;
for (int i = 0; i < totalrows; i++)
{
int status = Convert.ToInt32(dt.Rows[i]["is_busy"]);
Button ButtonAllLayout = new Button();
ButtonAllLayout.Name = "Layout'" + (i + 1) + "'";
ButtonAllLayout.Text = dt.Rows[i]["Layout_no"].ToString();
styleButton();//apply the button location...etc
this.Controls.Add(ButtonAllLayout);
if (status == 1)
{
ButtonAllLayout.BackColor = Color.Red;
}
else
{
ButtonAllLayout.BackColor = Color.YellowGreen;
}
}
}
}
}
catch (Exception)
{
throw;
}
}
private void button1_Click(object sender, EventArgs e)
{
refreshLayout();
}
Here's my code for MasterForm:
public MasterForm()
{
InitializeComponent();
}
private void BtnLayout_Click(object sender, EventArgs e)
{
Layout l1 = new Layout();
l1.refreshLayout();
splitContainerMain.Panel2.Show();
splitContainerMain.Panel2.Controls.Add(l1);
l1.Show();
}
private void BtnSetting_Click(object sender, EventArgs e)
{
Settings s1 = new Layout();
splitContainerMain.Panel2.Show();
splitContainerMain.Panel2.Controls.Add(s1);
s1.Show();
}
private void BtnMain_Click(object sender, EventArgs e)
{
Main m1 = new Main();
splitContainerMain.Panel2.Show();
splitContainerMain.Panel2.Controls.Add(m1);
m1.Show();
}
Can you please guide me how to do this?
Thanks in advance.

statusdefinitely updating from your DB? An aside note: is there any particular reason you're just re-throwing the exception without doing anything else? Have a read-up on handling exceptions :)catch (Exception) { throw; }?