Sri

Sri

  • NA
  • 11
  • 0

Treeview not expanding in MDI Child

Oct 22 2008 4:50 PM

Hi

I am getting an issue in expanding a treeview within the MDI Form.. When I try to run code to expand a treeview from normal form, it works perfectly. As soon as I try to call that form from a MDIForm it fails to expand by default.

Main Program Code
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new CDIM.Tracker.Modules.frmDashboard());
Application.Run(new TrackerMDI()); //Calling MDI
}
}

MDI Form code
public TrackerMDI()
{
InitializeComponent();

Form1 objForm1 = new Form1(); //This is the form that has treeview
objForm1.Visible = true;
objForm1.MdiParent = this; // this is making the treeview not to expand
objForm1.Show(); //Shows treeview without expanding any node
}

Form1 Code:
public Form1()
{
InitializeComponent();
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
InitializeTreeView();
}

// Populates a TreeView control with example nodes.
private void InitializeTreeView()
{
treeView1.BeginUpdate();
treeView1.Nodes.Add("Parent");
treeView1.Nodes[0].Nodes.Add("Child 1");
treeView1.Nodes[0].Nodes.Add("Child 2");
treeView1.Nodes[0].Nodes[1].Nodes.Add("Grandchild");
treeView1.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Great Grandchild");
treeView1.Nodes.Add("Parent");
treeView1.Nodes[1].Nodes.Add("Child 1");
treeView1.Nodes[1].Nodes.Add("Child 2");
treeView1.Nodes[1].Nodes[1].Nodes.Add("Grandchild");
treeView1.Nodes[1].Nodes[1].Nodes[0].Nodes.Add("Great Grandchild");
treeView1.EndUpdate();
treeView1.ExpandAll();
}

What can be the problem with MDIChild???


Answers (1)