Hi guys,
I want some help.
I want to get the form control which I have added in the tablelayoutpanel
using this code.
DataTable dtDashboardForms = objClsDataAccess.GetDataTable("select * from advt_dashboard_custom");
if (dtDashboardForms.Rows.Count > 0)
{
for (int i = 0; i < dtDashboardForms.Rows.Count; i++)
{
Form objForm = OpenForm(dtDashboardForms.Rows[i]["formloc"].ToString());
tblWidgetContainer.Controls.Add(objForm, Convert.ToInt32(dtDashboardForms.Rows[i]["column"]), Convert.ToInt32(dtDashboardForms.Rows[i]["row"]));
objForm.Dock = DockStyle.Fill;
objForm.Show();
}
}
public Form OpenForm(String formName)
{
Form oForm = null;
Type type = Type.GetType(formName, true);
Form obj = (Form)Activator.CreateInstance(type, ObjfrmCommonScreen);
obj.MdiParent = ObjfrmCommonScreen;
oForm = obj;
return oForm;
}
And after this all my Forms are added in the tablelayoutpanel.
And when I close any form through the tablelayoutpanel, I call this function on FormClosing event of the form:
public void Reset(Form obj)
{
TableLayoutPanel table = (TableLayoutPanel)this.Controls.Find("tblWidgetContainer", true).First();
int rowNumber = table.GetRow(obj);
int colNumber = table.GetColumn(obj);
for (int i = 0; i < table.RowCount; i++)
{
Form newForm = (Form)table.GetControlFromPosition(colNumber, i + 1);
if (newForm != null)
{
table.Controls.Add(newForm, colNumber, rowNumber);
}
}
obj.Dispose();
}
I am able to the row number and column number of the closing form using
int rowNumber = table.GetRow(obj);
int colNumber = table.GetColumn(obj);
And want to get the form at row+1 rownumber in the column,so the found form should take the place of the closing form.
but not able to get the form from this code:
Form newForm = (Form)table.GetControlFromPosition(colNumber, i + 1);
I used this code before and also able to get the control but that was the case of control.Not for the form.
So please help me to get the form object from the tablelayoutpanel column.
Hope you understand the question.
Thanks