views:

208

answers:

2

I have created a custom tree view control in .NET to display directories.

What I want is for the nodes to display the folder name and also the date last modified.

I can do this by just setting the text to include this but then when I try and get child nodes using full path it also includes the date and so the folder is not found.

So I tried overriding OnDrawNode to display the date as it is stored in the tag property of the node. However when I run the app it is never called.

Is there any reason for this?

+1  A: 

You must set the DrawMode property to OwnerDrawAll or OwnerDrawText. Otherwise, the nodes are drawn by the system, and OnDrawNode is not called


UPDATE : to combine the default rendering with your custom rendering, you can do that :

    protected override void OnDrawNode(DrawTreeNodeEventArgs e)
    {
        e.DrawDefault = true;
        base.OnDrawNode(e);
        // your custom rendering here
    }
Thomas Levesque
Thanks. Is there a way to draw the default but just also append some text to the node? It's a lot of work to get it looking like the default. Maybe it would be best changing the code so that I replace the date with blank before searching using full path?
dean nolan
see my updated answer
Thomas Levesque
Doh, how did I miss that :( Thanks, I'll try it later.
dean nolan
A: 

I have the very same problem, but in the opposite direction: I have larger text in the node.Text (because other reasons), and I would like to see smaller text displayed.

I do not want to draw all of the graphical elements (the tree lines, the background color etc.) I only want to change the displayed text, so I would like to use something like this:

protected override void OnDrawNode(DrawTreeNodeEventArgs e) {
 int pos = e.Node.Text.LastIndexOf('\\');
 if ( pos >= 0) {

// Change the node.Text temporarly. String s = e.Node.Text; e.Node.Text = s.Substring(pos + 1, s.Length - pos - 1); base.OnDrawNode(e); e.Node.Text = s; } else { base.OnDrawNode(e); }

return; }

But it doesn't work... Any idea?

Please ask this under a separate question.
Ian