How to show Multiline text on TreeView using C# 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • watsod1
    New Member
    • Nov 2006
    • 3

    #1

    How to show Multiline text on TreeView using C# 2005

    Hello,

    This is my first post, Hello to all. This also a test post to make sure that I am doing the right thing and following rules etc.

    I have been searching for a way to make the treeview display multiple lines of text on each treeview node (treenode).

    After searching for answers and not finding any, I stumbled on the solution in the msdn help files (search for TreeView.DrawNo de Event). It has source code that shows how to display multiple lines of text for a single node.

    You need to setup the treeview by changing the drawmode so that the text is draw by the _DrawNode event.

    Code:
    treeViewForTasks.DrawMode = TreeViewDrawMode.OwnerDrawText;
    I assign the node text, putting newlines in where I want. This text will be draw explicitly in the _DrawNode event handler.

    Code:
    childNode.Text = tr.Name + Environment.NewLine + tr.Description + Environment.NewLine + Environment.NewLine + "Incomplete";
    In the _DrawNode event handler, draw the node text, using the following code as an example. This code comes directly from the help documentation.

    Code:
    // Draw the node text.
    e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
    This is the result of my efforts so far. It still needs fine tuning, but it works, and thats all I care about at the moment.

  • watsod1
    New Member
    • Nov 2006
    • 3

    #2
    Here is a small demo of how to make a multiline treeview node



    Here is some source code sample App

    Comment

    Working...