Click here to Skip to main content
15,889,216 members
Articles / Programming Languages / Visual Basic

The TreeListView To End All TreeListViews

Rate me:
Please Sign up or sign in to vote.
4.77/5 (38 votes)
10 Jun 2008CPOL3 min read 379.7K   27.8K   145   162
An extensible, hybrid Listview/TreeListView control

Download Notes

  • WinControls.ListView.Components - Components only for those of you who don't want to mess around
  • WinControls.TreeListView - Source Code for the control
  • WinControls.TreeListViewSample - Sample project using the new control
TreeListView01.jpg

Introduction/Background

I actually started this code about four years ago when I needed a ListView/TreeListView combination control for a project I was working on. I soon discovered Jon Rista's article (listed below) here on CodeProject and I was off and running. I felt I could build upon his initial idea and with a little help from what others have written (also listed below) and my own ideas, I started it. Unfortunately, the project I was on folded but not the control itself. I continued the work and have been working on it here and there and now have finally gotten around to putting it on CodeProject.

I hope you all find this control useful. Invariably there will be issues, errors or better ways to do things when coding is involved. I am always open to new ideas and designs on my code so don't be afraid to let me know about it. If anyone has any issues, ideas or critiques you can post on the message board and hopefully I'll get to it ASAP.

Control Highlights

  • Comes with a fully documented help file generated by SandCastle (Sandcastle .shfb file included in project for future development)
  • Code is fully commented for Intellisense support
  • Full Design-Time support (including Columns - just click on them in the IDE)
  • Default Drag-n-Drop functionality built in (just turn it on)
  • Default sorting
  • Default folder images if you don't add your own
  • Icon support for columns
  • Checkbox/RadioButton support for the ContainerListView and TreeListView
  • Ability to show/hide individual Checkboxes/RadioButtons
  • Ability to enable/disable individual CheckBoxes/RadioButtons
  • Hidden columns
  • Column/Row Tracking
  • Export the control to XML and import it back in
  • Export the entire control or just the nodes
  • GridLine functionality for the ContainerListView and TreeListView controls
  • Separate ContextMenu for the Columns
  • On the fly support for editing individual ContainerListViewItems, ContainerListViewSubItems, and TreeListNodes
  • Support for changing the color of multiple properties of both controls, including GridLines, RootLines, Highlight color, etc...
  • Ability to show/hide RootLines, ChildLines, GridLines and PlusMinus signs
  • Adding controls to ContainerListViewSubItems
  • Alpha support for colors
  • FullPath support for TreeListNodes so you know where you are in the tree
  • Ability to change the Path character when getting the FullPath of a TreeListNode
  • Branching functionality for TreeListNodes which means you can highlight, color, select, disable, etc.. a subset of nodes/childnodes in a Tree
  • and much, much more!

Other Notes

  • Properties that are only stubbed out for future development will have 'Not Supported' in the designer and intellisense.
  • You may have to remove the source control bindings and files from the code.
  • The solutions have been ported over to Visual Studio 2008. However, the target framework is the .NET 2.0 Framework so you could port the code back to Visual Studio 2005 with no problems if necessary.
  • Extract the sample project to the same directory as the source project as the sample project references the source project. Otherwise, you will have to re-reference the source project.

Thank-You's

History

  • 10th June, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Subitem edit Pin
emoneta16-Feb-11 20:25
emoneta16-Feb-11 20:25 
GeneralRe: Subitem edit Pin
HelderPinto7917-Feb-11 23:22
HelderPinto7917-Feb-11 23:22 
GeneralRe: Subitem edit Pin
emoneta20-Feb-11 2:12
emoneta20-Feb-11 2:12 
Question.NET 4? Pin
Xyux20-Aug-10 4:31
Xyux20-Aug-10 4:31 
AnswerRe: .NET 4? Pin
Xyux20-Sep-10 1:13
Xyux20-Sep-10 1:13 
QuestionHow to get more checkboxes? Pin
T_uRRiCA_N17-Aug-10 1:29
professionalT_uRRiCA_N17-Aug-10 1:29 
QuestionHow to double-click the column edge line to resize column width for fiting max string width? Pin
stevenyoung3-Aug-10 21:11
stevenyoung3-Aug-10 21:11 
GeneralFix for slow rendering when long (4k+) text values are added. Pin
Sprotty21-Jul-10 6:13
Sprotty21-Jul-10 6:13 
The Tools.vb TruncateString function tries to work out the string that will fit in a given rectangle, it does this by measuring the string, if it does not fit it removes a char and measures again until it does. This is very slow for large strings, and I've seen it throw out of memory exceptions.

The following function converges on the result and is much faster.

I'm sure there should be a windows API to do this, but after a fair bit of looking nothing presented itself...
Let me know if there is a nice API that says the first x chars from this string will fit in this rect.


Public Shared Function TruncateString(ByVal aText As String, ByVal fontVal As Font, ByVal aWidth As Integer, ByVal aOffSet As Integer, ByVal aGr As Graphics) As String
Dim Sz As SizeF

' This function was very slow if large amounts of data were added
' This algorthum converges on teh solution, and is MUCH faster
Dim min As Integer = 0
Dim max As Integer = aText.Length
Dim testValue As Integer = Math.Min(200, max)

While (min < max)
Dim lastTestValue As Integer = testValue

Sz = aGr.MeasureString(aText.Substring(0, testValue), fontVal)
If Sz.Width > (aWidth - aOffSet) Then
If testValue = CInt(min + ((max - min) / 2)) Then
max = testValue - 1
End If
testValue = CInt(min + ((max - min) / 2))

ElseIf Sz.Width < (aWidth - aOffSet) Then

If testValue = CInt(min + ((max - min) / 2)) Then
min = testValue + 1
End If
testValue = CInt(min + ((max - min) / 2))
Else
' result
Return aText.Substring(0, testValue)
End If
End While
Return aText.Substring(0, testValue)
End Function
GeneralUnhandled exception while scrolling at the bottom of the control Pin
Lonewolf_v8-Jun-10 4:30
Lonewolf_v8-Jun-10 4:30 
AnswerRe: Unhandled exception while scrolling at the bottom of the control Pin
Anil_Mishra_Vyces6-May-11 23:11
Anil_Mishra_Vyces6-May-11 23:11 
GeneralRe: Unhandled exception while scrolling at the bottom of the control Pin
Jabberwock20-Jun-11 23:20
Jabberwock20-Jun-11 23:20 
GeneralRe: Unhandled exception while scrolling at the bottom of the control Pin
Jaf Alee29-Jan-12 11:12
Jaf Alee29-Jan-12 11:12 
QuestionHow to find text Pin
Umesh Sadavarte10-May-10 23:02
Umesh Sadavarte10-May-10 23:02 
GeneralImage in cell Pin
Gaudi11112-Feb-10 6:38
Gaudi11112-Feb-10 6:38 
QuestionGetting the Selected Node? Pin
GravityPhazer7-Feb-10 2:58
professionalGravityPhazer7-Feb-10 2:58 
AnswerRe: Getting the Selected Node? Pin
Ted Osberg7-Feb-10 3:49
Ted Osberg7-Feb-10 3:49 
GeneralRe: Getting the Selected Node? Pin
GravityPhazer7-Feb-10 5:37
professionalGravityPhazer7-Feb-10 5:37 
GeneralLove it Pin
bigteks25-Jan-10 6:09
bigteks25-Jan-10 6:09 
QuestionHow to use with VB6? Pin
Gaudi11116-Jan-10 7:37
Gaudi11116-Jan-10 7:37 
AnswerRe: How to use with VB6? Pin
Pijak W9-Apr-10 6:41
Pijak W9-Apr-10 6:41 
GeneralSize Image Pin
sergio582-Jan-10 2:58
sergio582-Jan-10 2:58 
Generaladd custom control to the subitems Pin
Member 404996323-Aug-09 15:24
Member 404996323-Aug-09 15:24 
AnswerRe: add custom control to the subitems Pin
nultof2-Aug-10 13:53
nultof2-Aug-10 13:53 
GeneralRe: add custom control to the subitems Pin
Member 40499632-Aug-10 16:59
Member 40499632-Aug-10 16:59 
GeneralRe: add custom control to the subitems Pin
AlexL22-Sep-10 3:38
AlexL22-Sep-10 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.