473,698 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

treeview identical to windows explorer tree

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
Nov 15 '05 #1
3 8835
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
-----Original Message-----
in windows explorer, the nodes immed under the "my computer" root nodeappear with a minimum of indenting ( the +/- square is directlyunderneath the root node ). In the .NET TreeView control the indentis shifted one more indent level to the right, wasting valuablehorizontal space.

How can I instruct TreeView to indent from the root node the same wayas windows explorer does?

thanks,

-Steve
.

Nov 15 '05 #2

Hi Steve,

I think I have tried Jacob's way, it realy appears like the windows
explorer.
But I think you need add the click event to the label control(Such as
expand the treeview).
Also, you should make the user can select your root node(actually the
lable's text). I think this need hit test, then draw the back color of your
label text.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
"Jacob" <an*******@disc ussions.microso ft.com> wrote in message news:<0a******* *************** ******@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.A dd( MyDocs ) ;
TreeNode MyComputer = new TreeNode( ... ) ;
Desktop.Nodes.A dd( 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,

-Steve
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
11538
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
4
12747
by: David Elliott | last post by:
Hi, I have a Windows Explorer-like treeview that displays directories. After a cut/paste operation, I want the treeview to display the folder where the paste happened. But, I'm running into a problem following the assignment of the selectednode in the treeview. Here's the relevant code: // separate the node names string split = mcurrentPath.Split(new Char {'\\'});
1
5215
by: Terry | last post by:
I've seen several posts from people who have seen this flashing in TreeView's when resizing a form. I've noticed it in my app, but only in the child windows. For example, my main form has a splitter with a TreeView and I do not get the flickering with it. I created a new Form based Windows app. Added a TreeView (dock left), then a splitter and a property grid on the right (dock fill). For this test, I added a panel and button at the...
4
7594
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
8
4402
by: Hrvoje Voda | last post by:
What is wrong in this code? private void tree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter ) {
4
14175
by: Ben Coats | last post by:
Hey, I'm trying to find code for an Explorer-style Directory ComboBox. (You know, it display "Desktop", "My Computer", all drives, etc., but it has a treeview control inside the combobox so that you can navigate through the file system as well.) I've found some on the web, but all of them just have the drives and desktop directories and are static in that you cannot expand the directories. I normally build a treeview control to do it with,...
6
4928
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
12
587
by: Bob Hollness | last post by:
Hi. I have a text file containing a list of files and their path. I.e. c:\MyDocs\File1.txt c:\MyDocs\File2.txt c:\MyDocs\File3.txt c:\MyDocs\File4.txt C:\MyDocs\Folder\File1.txt
2
7495
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView nodes. The TreeView populates dynamically as there are a significant number of nodes. The DataGrid displays both the items and the nodes from the TreeView. Using the explorer analogy this means the TreeView shows folders, and the DataGrid folders...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.