Question

Is it possible (by using the stock c# TreeView) to have Multiline TreeNodes?

Also, is it possible to add control characters to TreeNode's text e.g. '\t'? This same effect could also be achieved by adding columns to the TreeNode. is this possible?

Was it helpful?

Solution

I do not believe this is possible using WinForms, at least without drawing your own nodes. You may be able to use an "owner-drawn" treenode to accomplish this in WinForms, though, I don't know.

This is natively supported with WPF, though.

OTHER TIPS

It isn't very clear from your question whether you are on ASP.NET or WinForms. If you're in ASP.NET you could try using the PRE tag to get formatting...?

What that's said the Ra-Ajax TreeView which you can see an example of here can have any arbitrage amount of HTML and/or even controls within it which mostly makes it way superior to the built in TreeView in ASP.NET. (Disclaimer; I Work with Ra-Ajax)

This makes it possible for you to format the contents of the TreeView exactly as you wish. Though if you go completely berserk you still run the risk of creating "display artifacts" due to too much space or something like that...

It is not possible to use the tabulator effectively inside a TreeNode. Anyways, I have a workaround:

The Font "Consolas" has equal space of each letter so you can space easily with blanks. The method GetEmptyInfoByIndex returns a custom lenght string of spaces to fill the gap until a specified length. Here = 20.

mynode.NodeFont = new System.Drawing.Font("Consolas", 9,FontStyle.Regular);

string displaytext = String.Format(CultureInfo.InvariantCulture, "{0}{2} = {1}", mystringOfDifferentLenght, myresult, GetEmptyInfoByIndex(mystringOfDifferentLength, 20));
mynode.Text = displaytext;
rootnode.Nodes.Add(mynode);

private string GetEmptyInfoByIndex(string _string, int maxLength)
    {
        string retstr = string.Empty;
        for (int i = 0; i < maxLength - _string.Length; i++)
        {
            retstr += " ";
        }
        return retstr;
    }

Proof here!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top