Results 1 to 6 of 6

Thread: Help NullReferenceException was unhandled when coding with treeview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    23

    Help NullReferenceException was unhandled when coding with treeview

    I am new to vb.net 2005 and am desperate in need of solution as I faced error on the following codes.

    Public Class Form1
    Private PreviousTab As TabControl
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
    ListNodes(TreeView1.Nodes(0))
    With TreeView1.Nodes.Item("AdminMenu")
    .Nodes.Item("AddCustomer").Tag = TabAddCust
    .Nodes.Item("DeleteCust").Tag = TabDeleteCust
    End With
    End Sub
    Private Sub ListNodes(ByVal StartNode As TreeNode)
    Debug.WriteLine(StartNode.Name)
    For Each n As TreeNode In StartNode.Nodes
    ListNodes(n)
    Next
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    If PreviousTab IsNot Nothing Then
    PreviousTab.Visible = False
    End If
    If e.Node.Tag IsNot Nothing Then
    Dim ActiveTab As TabControl = CType(e.Node.Tag, TabControl)
    ActiveTab.Visible = True
    ActiveTab.Dock = DockStyle.Fill
    PreviousTab = ActiveTab
    End If
    End Sub

    When I run the program two lines of the code face error message of NullReferenceException was unhandled.

    .Nodes.Item("AddCustomer").Tag = TabAddCust
    .Nodes.Item("DeleteCust").Tag = TabDeleteCust

    I am clueless on how to solve this.

    Please help me!!!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Help NullReferenceException was unhandled when coding with treeview

    You need to verify that TreeView1 contains a node with the key "AdminMenu" that in turn holds two nodes with the keys "AddCustomer" and "DeleteCust".

    Furthermore, you should post all your VB.Net questions in the VB.Net forum, a moderator will probably move this thread as soon as possible.
    And you should wrap your code in [HIGHLIGHT=VB.Net][/HIGHLIGHT] tags.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help NullReferenceException was unhandled when coding with treeview

    Thread Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    23

    Re: Help NullReferenceException was unhandled when coding with treeview

    Thanks for the answer.

    Could you give me some tips on how to verify the nodes given the Admin Menu node as the root node and the child node is AddCustomer? I need sample coding to understand because I just started learning visual basic.net less than a month.

    So sorry for using the wrong forum I think being awake for too long figuring out solution makes me blur .

  6. #6
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: Help NullReferenceException was unhandled when coding with treeview

    please help me, i have big problem in my solutions projects in visual studio 2005

    System.NullReferenceException was unhandled
    Message="Object reference not set to an instance of an object."
    Source="MBSControls"
    StackTrace:
    at MBSControls.ListViewXTC.InitializeList(Object items) in C:\Projects\TimeSheet\MBSControls\ListViewXTC.cs:line 208

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width