I have MainForm and Form2 is displayed in panel of Mainform.(Looks like MDI form but not MDI as I have heard that MDIForm is bad idea)
When I Check the RowCount Of datagridview1 displayed on Form2 in Mainform.cs or
any other form the datagridview1.RowCount is always one.
I have also found that
Form2.IsHandleCreated is always false .Even If I see the Form2 displayed in Mainform panel.
So I have created handle by
CreateControl method for Form2 and datagridview1.
but still Form2.IsHandleCreated is false.
datagridview1.ISHandle is false ALWAYS.WHY?WHY?WHY?.
also tried
I have tried a lot but not found any solution for this.
And I know how to use delegate to write values from different thread.
I have written values of Maindatagridview from thread because I can see Its
RowCount is What I have entered(more than one).
So I only want the solution for why RowCount is always one in Child Form2.
This is happening with every child form.
Becasue of this problem I am not able to write values to datagridview from any other
form ,even from Mainform.
Question Improved
//
Code 1
How I have created Form2 In MainForm
private Form CreateForm(ControlsEnum frm)
{
switch (frm)
{
case ControlsEnum.Form2:
return new Form2();
case... number of forms
default: return null;
}
}
public void ShowForm(ControlsEnum frm)
{
Form new_Frm = null;
if (controls.ContainsKey(frm))
{
new_Frm = controls[frm];
}
else
{
new_Frm = CreateForm(frm);
controls[ctrl] = new_Frm;
new_Frm.TopLevel = false;
}
new_Frm.Parent = this;
new_Frm.Dock = DockStyle.Fill;
new_Frm.BringToFront();
ShowFormPanel_PNL.Controls.Add(new_ctrl);
new_ctrl.Show();
}
void Mainform_Load()
{
if replaced the above line with below code I get results
f2 = new Form2();
f2.TopLevel = false;
ShowFormPanel_PNL.Controls.Add(f2);
f2.Show();
}
// When Form2 and Mainform displayed. I add dynamically rows to gridview from a button on Form2.
//then I click MainFormbutton1
private void MainFormbutton1_Click(object sender, EventArgs e)
{
Program.f2 = f2;
int x= Program.f2.From2GridView.Rows.Count;
int y = f2.From2GridView.Rows.Count;
}