To my knowledge... you can't. But you can fake it. And I
always say, where you can fake it.... er, uh... you can
fake it.
Set the TreeView's border to none. Add a label just above
the TreeView with the label's BackColor set to the same
as the TreeView's and turn it's border off as well. It
shouldn't be difficult to line up the Label just above
the TreeView and get it to look like it's part of the
same control. Then just wire up the label's click event
to refresh the TreeView and process anything else that
you want(like collapsing all nodes). If you want to
complete the illusion, put both the Label and TreeView on
a Panel control, set their docking and anchor properties
to extend to the edges of the panel, and turn the panel's
border property on.
It could fool even the best trained eye.
Good Luck,
Jacob
[quoted text, click to view] >-----Original Message-----
>in windows explorer, the nodes immed under the "my
computer" root node
>appear with a minimum of indenting ( the +/- square is
directly
>underneath the root node ). In the .NET TreeView
control the indent
>is shifted one more indent level to the right, wasting
valuable
>horizontal space.
>
>How can I instruct TreeView to indent from the root node
the same way
>as windows explorer does?
>
>thanks,
>
>-Steve
>.
[quoted text, click to view] "Jacob" <anonymous@discussions.microsoft.com> wrote in message news:<0af801c3b2a5$d2df66b0$a501280a@phx.gbl>...
> To my knowledge... you can't. But you can fake it. And I
> always say, where you can fake it.... er, uh... you can
> fake it.
>
> Set the TreeView's border to none. Add a label just above
> the TreeView with the label's BackColor set to the same
> as the TreeView's and turn it's border off as well. It
> shouldn't be difficult to line up the Label just above
> the TreeView and get it to look like it's part of the
> same control. Then just wire up the label's click event
> to refresh the TreeView and process anything else that
> you want(like collapsing all nodes). If you want to
> complete the illusion, put both the Label and TreeView on
> a Panel control, set their docking and anchor properties
> to extend to the edges of the panel, and turn the panel's
> border property on.
that looks neat Jacob, thanks.
Turns out I was making a mistake in which node I was adding the sub
nodes to. I was doing something like this:
TreeView tv = new TreeView( ... ) ;
TreeNode Desktop = new TreeNode( ... ) ;
tv.Nodes.Add( Desktop ) ;
// now I start to make my mistake. I add "My Documents" and "My
Computer"
// as sub nodes of the DesktopNode.
TreeNode MyDocs = new TreeNode( ... ) ;
Desktop.Nodes.Add( MyDocs ) ;
TreeNode MyComputer = new TreeNode( ... ) ;
Desktop.Nodes.Add( MyComputer ) ;
// the nodes line up better when "My Documents" and "My Computer" are
nodes
// of the TreeView the same as the "Desktop" node.
tv.Nodes.Add( MyDocs ) ;
tv.Nodes.Add( MyComputer ) ;
thanks for the help,