title: How to extract Information from Nodes in TreeView in Windows forms?
body: <p>I have created a Winform. I want to show Subanatomy ID information using object of type Subanatomy after the node is selected how Should I do it.?
  i have used all the neccessary libraries in my original code <a href="https://i.stack.imgur.com/YyG6L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YyG6L.png" alt="enter image description here"></a></p>
  
  <pre><code>`    using System.Windows.Forms;
   using basicObjectLib;
  
  namespace WindowsFormsApplication12
  {
  public partial class Form1 : Form
  {
  
  
  
      public Form1()
      {
          InitializeComponent();
          LoadTreeItems();
   }
  
      public void LoadTreeItems()
      {
          // Dummy Data 
          // created a DLL Basic Class Object Conatining class definitions of anatomy subanatomy 
          #region Object
          Anatomy an1 = new Anatomy();
          an1.AnatomyID = 1;
          an1.AnatomyName = "Anatomy1";
  
          Subanatomy san1 = new Subanatomy();
          san1.SubAnatomyID = 11;
          san1.SubAnatomyName = "subAn1";
          an1.SubanatomyList.Add(san1);
  
          Subanatomy san2 = new Subanatomy();
          san2.SubAnatomyName = "subAn2";
          san2.SubAnatomyID = 2;
          an1.SubanatomyList.Add(san2);
  
  
          Anatomy an2 = new Anatomy();
          an2.AnatomyID = 2;
          an2.AnatomyName = "Anatomy2";
  
          Subanatomy san21 = new Subanatomy();
          san21.SubAnatomyName = "subAn1";
          san21.SubAnatomyID = 21;
          an2.SubanatomyList.Add(san21);
  
          Subanatomy san22 = new Subanatomy();
          san22.SubAnatomyName = "subAn2";
          san22.SubAnatomyID = 22;
          an2.SubanatomyList.Add(san22);
  
  
          Anatomy an3 = new Anatomy();
          an3.AnatomyID = 3;
          an3.AnatomyName = "Anatomy3";
  
          Subanatomy san31 = new Subanatomy();
          san31.SubAnatomyName = "subAn1";
          san31.SubAnatomyID = 31;
          an3.SubanatomyList.Add(san31);
  
          Subanatomy san32 = new Subanatomy();
          san32.SubAnatomyName = "subAn2";
          san32.SubAnatomyID = 32;
          an3.SubanatomyList.Add(san32);
  
          List&lt;Anatomy&gt; anatomyObj = new List&lt;Anatomy&gt;();
          anatomyObj.Add(an1);
          anatomyObj.Add(an2);
          anatomyObj.Add(an3);
          #endregion
  
          foreach(Anatomy obj in anatomyObj)
          {
              TreeNode parentNode = new TreeNode();
             parentNode = new TreeNode(obj.AnatomyName);
  
              treeView1.Nodes.Add(parentNode);
              foreach(Subanatomy subObj in obj.SubanatomyList)
              {
                  TreeNode childNode = new TreeNode();
                  childNode = new TreeNode(subObj.SubAnatomyName);
  
                  parentNode.Nodes.Add(childNode);
              }
          }
  
  
      }
      private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
      {
  
          if (e.Action == TreeViewAction.ByMouse)
          {
              // name of treeNode
              textBox4.Text = treeView1.SelectedNode.Name.ToString();
              // to show the ID
              textBox2.Text = "";
          }
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          treeView1.ExpandAll();
      }
    }
    public class WindowsFormApplication
    {
      public static void main()
      {
          Form1 _treeviewDemo = new Form1();
  
      }
   }
  }`
  </code></pre>