Click here to Skip to main content
12,248,777 members (40,267 online)
Click here to Skip to main content

Stats

109.3K views
6 downloads
49 bookmarked
Posted

Mole II for WPF

, , , 31 Dec 2007 CPOL
Introduces the second version of a very useful and educational debugger visualizer for WPF developers.
Mole_Visualizer_2_1_1_VS2008_SourceAndTestProject.zip
Mole_Visualizer_2_1_1_VS2005_SourceAndTestProject.zip
Mole_Visualizer_2_1_1_VS2005_Release.zip
Mole_Visualizer_2_1_1_VS2008_Release.zip
Mole.Visualizer.dll
Mole.Visualizer
Custom Controls
Data Source
Image Processing
Data
Debugger Visualizer
Enums Constants
Event Args
Extended Controls
Images
MoleVisualUnavailable.gif
Mole.Visualizer.csi
Mole.Visualizer.suo
Mole.Visualizer.vbproj.user
My Project
Application.myapp
Settings
Visualizer UI
XSLT
Mole.TestBench
bach.jpg
Mole.TestBench.csi
Mole.TestBench.suo
My Project
Mole.Visualizer.dll
bach.jpg
Mole.TestBench.csi
Mole.TestBench.suo
MoleVisualUnavailable.gif
Mole.Visualizer.csi
Mole.Visualizer.suo
Mole.Visualizer.vbproj.user
Application.myapp
Mole.Visualizer.dll
MoleVisualUnavailable.gif
Mole.Visualizer.csi
Mole.Visualizer.suo
Mole.Visualizer.vbproj.user
Application.myapp
bach.jpg
Mole.TestBench.csi
Mole.TestBench.suo
Mole.Visualizer.dll
MoleVisualUnavailable.gif
Mole.Visualizer.csi
Mole.Visualizer.suo
Mole.Visualizer.vbproj.user
Application.myapp
bach.jpg
Mole.TestBench.csi
Mole.TestBench.suo
Mole.Visualizer.dll
MoleVisualUnavailable.gif
Mole.Visualizer.csi
Mole.Visualizer.suo
Mole.Visualizer.vbproj.user
Application.myapp
bach.jpg
Mole.TestBench.csi
Mole.TestBench.suo
Mole.Visualizer.dll
MoleVisualUnavailable.gif
Mole.Visualizer.csi
Mole.Visualizer.suo
Mole.Visualizer.vbproj.user
Application.myapp
bach.jpg
Mole.TestBench.csi
Mole.TestBench.suo
Imports System.Windows.Forms
Imports System.ComponentModel

Public Class MoleTreeView
    Inherits TreeView

#Region " Declarations "

    Private _objInitialNode As MoleTreeNode
    Private _objTree As Tree

#End Region

#Region " Properties "

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), _
     Browsable(False)> _
    Public Property TreeData() As Tree
        Get
            Return _objTree
        End Get
        Set(ByVal value As Tree)

            If value Is Nothing Then
                Throw New ArgumentNullException("TreeData")
            End If

            _objTree = value
            Me.Nodes.Clear()

            Dim objRootMoleTreeNode As MoleTreeNode = New MoleTreeNode(_objTree.RootElement)
            Me.Nodes.Add(objRootMoleTreeNode)
            LocateInitialNode(objRootMoleTreeNode, _objTree.InitialElementId)

            If _objInitialNode IsNot Nothing Then
                _objInitialNode.BackColor = Drawing.Color.LightGreen
                SelectInitialNode()
            End If

            SelectInitialNode()
        End Set
    End Property

#End Region

#Region " Methods "

    ''' <summary>
    ''' This is Josh Smith's awesome lazy load code.  I was using a different approach but his is just better so I'm going Josh here.
    ''' </summary>
    Private Sub LazyLoadChildNodes(ByVal objParentMoleTreeNode As MoleTreeNode)
        objParentMoleTreeNode.Nodes.Clear()

        For Each objTreeElement As TreeElement In objParentMoleTreeNode.TreeElement.Children
            objParentMoleTreeNode.Nodes.Add(New MoleTreeNode(objTreeElement))
        Next

    End Sub

    ''' <summary>
    ''' This is Josh Smith's awesome lazy load code.  I was using a different approach but his is just better so I'm going Josh here.
    ''' </summary>
    Private Sub LocateInitialNode(ByVal objMoleTreeNode As MoleTreeNode, ByVal intInitialElementID As Integer)

        If objMoleTreeNode.TreeElement.Id = intInitialElementID Then
            _objInitialNode = objMoleTreeNode

        Else
            LazyLoadChildNodes(objMoleTreeNode)

            Dim objTargetMoleTreeNode As MoleTreeNode = Nothing

            For Each objChildNode As MoleTreeNode In objMoleTreeNode.Nodes

                If intInitialElementID < objChildNode.TreeElement.Id Then
                    Exit For
                End If

                objTargetMoleTreeNode = objChildNode
            Next

            If objTargetMoleTreeNode IsNot Nothing Then
                LocateInitialNode(objTargetMoleTreeNode, intInitialElementID)
            End If

        End If

    End Sub

    Public Sub SelectFirstNode()

        If Me.Nodes.Count <> 0 Then
            Me.SelectedNode = Me.Nodes(0)
            Me.SelectedNode.EnsureVisible()
            Me.Focus()
        End If

    End Sub

    Public Sub SelectInitialNode()

        If _objInitialNode IsNot Nothing Then
            Me.SelectedNode = _objInitialNode
            Me.SelectedNode.EnsureVisible()
            Me.Focus()
        End If

    End Sub

    Protected Overrides Sub OnBeforeExpand(ByVal e As System.Windows.Forms.TreeViewCancelEventArgs)
        MyBase.OnBeforeExpand(e)

        If e.Node IsNot Nothing AndAlso e.Node.Nodes.Count = 1 AndAlso String.Compare(e.Node.Nodes(0).Text, STRING_MOLE_DUMMY_TREENODE_MARKER, StringComparison.Ordinal) = 0 Then
            LazyLoadChildNodes(DirectCast(e.Node, MoleTreeNode))
        End If

    End Sub

#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Authors

Andrew Smith
Architect Infragistics, Inc.
United States United States
Andrew currently works as an architect for Infragistics working with windows forms and WPF. You can check out his blog here.

Josh Smith
Software Developer (Senior) Cynergy Systems
United States United States
Josh creates software, for iOS and Windows.

He works at Cynergy Systems as a Senior Experience Developer.

Read his iOS Programming for .NET Developers[^] book to learn how to write iPhone and iPad apps by leveraging your existing .NET skills.

Use his Master WPF[^] app on your iPhone to sharpen your WPF skills on the go.

Check out his Advanced MVVM[^] book.

Visit his WPF blog[^] or stop by his iOS blog[^].

Karl Shifflett
Architect
United States United States

Current passions are: Electron, ES6, Node.js, Angular, Aurelia, hybrid, Socket.IO, MQTT, and IoT.

Still keen on WPF and Prism, but currently Electron and ES6 deliver the same apps with much better performance, and they are cross-platform.

My Github Repros

Just a grain of sand on the worlds beaches.


You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 31 Dec 2007
Article Copyright 2007 by Andrew Smith, Josh Smith, Karl Shifflett
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid