Multiline treeview possible?

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

Can anyone think of a way or point me in the right direction to be able to
get a multiline treeview? By this I mean that each TreeNode Label can span
say 2 lines (delimited by \n)?

Thanks!
-Dan
 
DS said:
Can anyone think of a way or point me in the right direction to be able to
get a multiline treeview? By this I mean that each TreeNode Label can span
say 2 lines (delimited by \n)?

Just to clarify with a bit of an example:
+ John Doe
Widgets Inc.
-Home Contact
-Work Contact
+ Jane Doe
SomeCo.
-Headoffice Contact
-International Contact

In this case treeNode1.Text = "John Doe\nWidgets Inc.", with 2 child nodes
beneath it; treeNode2.Text = "Jane Doe\nSomeCo.", also with 2 child nodes.
Make sense?

Thanks :-)
 
DS said:
Just to clarify with a bit of an example:
+ John Doe
Widgets Inc.
-Home Contact
-Work Contact
+ Jane Doe
SomeCo.
-Headoffice Contact
-International Contact

In this case treeNode1.Text = "John Doe\nWidgets Inc.", with 2 child nodes
beneath it; treeNode2.Text = "Jane Doe\nSomeCo.", also with 2 child nodes.
Make sense?

Hey guys, I posted this message a few days ago and got no response.. I'm
hoping that someone has at least played with this or can give me some
advice.

Thanks again,
Dan
 
DS said:
Hey guys, I posted this message a few days ago and got no response.. I'm
hoping that someone has at least played with this or can give me some
advice.

Thanks again,
Dan

Hi Dan!

I want to show you an example. I haven't checked for errors, but can give
you an Idea. Hope it helps.

Best Regard
Hans

//---------------------------------------------
private TreeView trvContact = new TreeView();

private string [] RootArray = new string [2];
private string [] Child1Array = new string [2];
private string [] Child2Array = new string [2];

private void initialize_ArrayList ()
{
this.RootArray[0] = "John Doe\nWidgets Inc";
this.RootArray[1] = "Jane Doe\nSomeCo.";

this.Child1Array[0] = "Home Contact";
this.Child1Array[1] = "Work Contact";

this.Child2Array[0] = "HeadOffice Contact";
this.Child2Array[1] = "International Contact";
}//initialize_ArrayList

private void initialize_TreeView ()
{
//locate TreeView
this.trvContact.Location = new point (0,0); //upper left corner
this.trvContact.Size = new Size (200, 400); //width and hight
this.Controls.Add (this.trvContact);

//Add parent to tree
for (int p = 0; p < this.RootArray.Length; p++)
{
TreeNode ChildNode = new TreeNode(RootArray[p].ToString());
ChildNode.Tag = p //a suitable number
this.trvContant.Nodes.Add (ChildNode);
}//for RootArray

//Add ChildNode 1 to ParentNode 2
for (int p = 0; p < this.Child1Array.Length; p++)
{
TreeNode ChildNode = new TreeNode(this.Child1Array[p].ToString());
ChildNode.Tag = 100 + p //a suitable number
this.trvContant.Nodes[0].Nodes.Add (ChildNode);
}// for Child1Array

//Add ChildNode 2 to ParentNode 2
for (int p = 0; p < this.Child2Array.Length; p++)
{
TreeNode ChildNode = new TreeNode(this.Child2Array[p].ToString());
ChildNode.Tag = 200 + p //or a suitable number
this.trvContant.Nodes[1].Nodes.Add (ChildNode);
}// for Child1Array
}//initialize_TreeView

private void Form1_Load (object sender, System.EventArgs e)
{
this.initialize_ArrayList ();
this.initialize_TreeView ();
}
//------------------------------------------------------
 
Hans said:
Hi Dan!

I want to show you an example. I haven't checked for errors, but can give
you an Idea. Hope it helps.

Best Regard
Hans

<code snipped>

Hi Hans,
Thanks for the reponse, but thats similar to what I tried before (that being
using a '\n' in the treeNode.Text field). What you end up with is a []
looking character (one of the weird unicode boxes) and everything still on a
single line (except for the child nodes of course being a level deeper). Any
other ideas? Is there perhaps a way for me to easily inherit the
functionality of the treeview into a control of my own and just rewrite the
way it renders text? I have no clue where to even begin with this approach,
so any help would certainly be appreciated!

Cheers,
Dan
 
Back
Top