title: C#: Help determining selected node index in a TreeView. NullReferenceException error?
body: <p>I'm trying to make it so I can run certain events when a node is selected in a TreeView. I run the code and I get an error that reads NullReferenceException was unhandled: Object reference not set to an instance of an object.</p>
  
  <p>Any clues on how to overcome this obstacle?</p>
  
  <pre><code>    private void tvNodes_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
      {
          switch (tvNodes.SelectedNode.Index)
          {
              case 0:
                  //first item
                  break;
  
              case 1:
                  //second item
                  break;
  
              case 2:
                  //third item
                  break;
          }
      } 
  </code></pre>