jeudi 12 mars 2015

Treeview created at runtime not displaying nodes

I have two treeview controls, one is manually added at design time and the other is created at runtime. The string ParentNode should be displayed on both sides of the panels but it's not displaying on the treeview created at runtime. I'm not sure if it's something basic I'm missing or if the custom control Accordion is the problem.


Why is runTimecustomTreeView not displaying the node?


Link to dropbox solution http://ift.tt/1B9VfTh


enter image description here


Code:



using ExpanderApp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private CustomTreeView runTimecustomTreeView = new CustomTreeView();

public Form1()
{
InitializeComponent();
CreateAccordion();
BuildTreeViewTest1();
BuildTreeViewTest2();
}

private void BuildTreeViewTest1()
{
//Control Added design time
customTreeView1.Nodes.Add("ParentNode");
}

private void BuildTreeViewTest2()
{
//Control Added run time
runTimecustomTreeView.Nodes.Add("ParentNode");
}

private void CreateAccordion()
{
Accordion accordion = new Accordion();
accordion.Dock = DockStyle.Fill;
Expander expander1 = new Expander();
expander1.BorderStyle = BorderStyle.FixedSingle;
ExpanderHelper.CreateLabelHeader(expander1, "Navigation", SystemColors.ActiveBorder);
runTimecustomTreeView.Dock = DockStyle.Fill;
expander1.Controls.Add(runTimecustomTreeView);
accordion.Add(expander1);

splitContainer1.Panel1.Controls.Add(accordion);
}


private void CreateContentLabel(Expander expander, string text, int height)
{
Label labelContent = new Label();
labelContent.Text = text;
labelContent.Size = new System.Drawing.Size(expander.Width, height);
expander.Content = labelContent;
}
}


//Treeview subclass to prevent double clicking checkboxes
class CustomTreeView : TreeView
{
protected override void WndProc(ref Message m)
{
// Filter WM_LBUTTONDBLCLK
if (m.Msg != 0x203) base.WndProc(ref m);
}
}
}

Aucun commentaire:

Enregistrer un commentaire