473,748 Members | 2,361 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 8839
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
11548
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
12749
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
5216
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
7598
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
4407
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
14179
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
4934
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
7498
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
8822
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
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9359
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
9310
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
6072
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
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
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
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.