title: How to trigger TreeView NodeMouseClick and CursorChanged events with a method. I am getting error on parameter `e` due to incompatible parameters
body: <p>I managed to create a <code>TreeView</code> method for <code>NodeMouseClick</code> and <code>CursorChanged</code> events.</p>
  <pre><code>private void Node_Selection_Action(object sender, TreeNodeMouseClickEventArgs e)
  {
      // my action code here...
  }
  
  private void TvwPanel_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  {
      Node_Selection_Action(sender, e);
  }
  </code></pre>
  <p>However, I am getting an error on <code>e</code> parameter when I applied the method to the <code>CursorChanged</code>:</p>
  <pre><code>private void TvwPanel_CursorChanged(object sender, EventArgs e)
  {
      Node_Selection_Action(sender, e); //error on `e` here
  }
  </code></pre>
  <p>I supposed this is due to the parameter <code>EventArgs</code> that is not compatible with my method parameter <code>TreeNodeMouseClickEventArgs</code>.</p>
  <p>Is there any workaround that I could use to trigger the <code>CursorChanged</code> event with my method?</p>
  <p><strong>UPDATE 1:</strong></p>
  <p>As requested, here's the bunch of code for the <code>Node_Selection_Action</code> method:</p>
  <pre class="lang-cs prettyprint-override"><code>    private void Node_Selection_Action(object sender, TreeNodeMouseClickEventArgs e)
              {                    
                  TvwPanel.SelectedNode = e.Node;
                  if (Convert.ToString(e.Node.Tag) == &quot;a&quot;) //profile Convert.ToInt16()
                  {
                      TsmNewPr.Enabled = false;
                      TsmNewDb.Visible = false;
                      TsmNewCo.Visible = false;
                      TsmNewTk.Visible = false;
                      TsmNewTkCred.Visible = false;
                      TsmNewLg.Visible = false;
      
                      TsmEditPr.Enabled = true;
                      TsmEditDb.Visible = false;
                      TsmEditCo.Visible = false;
                      TsmEditTk.Visible = false;
                      TsmEditTkCred.Visible = false;
                      TsmEditLg.Visible = false;
      
                      TsmDeletePr.Enabled = true;
                      TsmDeleteDb.Visible = false;
                      TsmDeleteCo.Visible = false;
                      TsmDeleteTk.Visible = false;
                      TsmDeleteTkCred.Visible = false;
                      TsmDeleteLg.Visible = false;
      
                      TsmRunTk.Enabled = false;
                      TsmRefreshLg.Enabled = false;
                      TsmHelpAll.Enabled = true;
                  }
                  else if (Convert.ToString(e.Node.Tag) == &quot;b&quot;) //database
                  {
                      TsmNewPr.Visible = false;
                      TsmNewDb.Enabled = true;
      
                      // arbitrary control if database already exists. If exists disable, otherwise enable.
                      #region TsmNewDb.Enabled (true/false)                               
      
                      selNodeParentName = TvwPanel.SelectedNode.Parent.Text;
                      selNodeName = TvwPanel.SelectedNode.Text;
      
                      Save_Treeview_To_Xml xcf = new Save_Treeview_To_Xml();
                      XElement xmlComplete = XElement.Load(xcf.xmlProfileComplete);
      
                      IEnumerable&lt;XElement&gt; profile =
                          from ep in xmlComplete.Elements(&quot;node&quot;)
                          where (string)ep.Attribute(&quot;text&quot;) == selNodeParentName
                          select ep;
      
                      foreach (XElement epi in profile)
                      {
                          IEnumerable&lt;XElement&gt; profNode =
                          from en in epi.Elements(&quot;node&quot;)
                          where (string)en.Attribute(&quot;text&quot;) == selNodeName
                          select en;
      
                          foreach (XElement enc in profNode)
                          {
                              // get the attribute texts
                              var childrenTexts = enc.Elements(&quot;node&quot;).Attributes(&quot;text&quot;);
      
                              foreach (var childText in childrenTexts)
                              {
                                  if (childText.Value != &quot;Type&quot; || childText.Value != &quot;Name&quot; || childText.Value != &quot;Connection&quot;)
                                  {
                                      // enable TsmNewDb ContextMenu button if does not exists yet
                                      TsmNewDb.Enabled = false;
                                  }
                              }
      
                              // initialize the attribute tags to null
                              string TypeTag = null;
                              string NameTag = null;
                              string ConnTag = null;
      
                              // get the attribute tags
                              var childrenTags = enc.Elements(&quot;node&quot;).Attributes(&quot;tag&quot;);
      
                              int count = 0;
                              // get db details for showing on the right panel of the main form specified below
                              foreach (var childTag in childrenTags)
                              {
                                  if (count == 0)
                                  {
                                      TypeTag = childTag.Value;
                                  }
                                  else if (count == 1)
                                  {
                                      NameTag = childTag.Value;
                                  }
                                  else if (count == 2)
                                  {
                                      ConnTag = childTag.Value;
                                  }
      
                                  count++;
                              }
      
                              // check if database exists
                              if (db.Databases_Exists(ConnTag) == true)
                              {
                                  // convert the password to &quot;*&quot; for display purposes
                                  string s = ConnTag;
                                  int start = s.LastIndexOf(&quot;pwd=&quot;) + &quot;pwd=&quot;.Length;
                                  int end = s.IndexOf(&quot;;&quot;, start);
                                  string result = s.Substring(start, end - start);
                                  s = s.Replace(result, &quot;********&quot;);
                                  ConnTag = s;
      
                                  // transfer data FrmDatabase form to main form tabcontrol panel
                                  LblDbTypeDef.Text = TypeTag;
                                  LblDbNameDef.Text = NameTag;
                                  LblDbConnDef.Text = ConnTag;
      
                                  // make the main tabcontrol panel visible to true
                                  TbcMain.SelectedIndex = 0;
                                  TbcMain.Visible = true;
                              }
                              else
                              {
                                  // make the main tabcontrol panel visible to false
                                  TbcMain.SelectedIndex = 0;
                                  TbcMain.Visible = false;
                              }
                          }
                      }
      
                      #endregion
      
                      TsmNewCo.Visible = false;
                      TsmNewTk.Visible = false;
                      TsmNewTkCred.Visible = false;
                      TsmNewLg.Visible = false;
      
                      TsmEditPr.Visible = false;
                      TsmEditDb.Enabled = true;
                      TsmEditCo.Visible = false;
                      TsmEditTk.Visible = false;
                      TsmEditTkCred.Visible = false;
                      TsmEditLg.Visible = false;
      
                      TsmDeletePr.Visible = false;
                      TsmDeleteDb.Enabled = true;
                      TsmDeleteCo.Visible = false;
                      TsmDeleteTk.Visible = false;
                      TsmDeleteTkCred.Visible = false;
                      TsmDeleteLg.Visible = false;
      
                      TsmRunTk.Enabled = false;
                      TsmRefreshLg.Enabled = false;
                      TsmHelpAll.Enabled = true;
                  }
                  else if (Convert.ToString(e.Node.Tag) == &quot;c&quot;) //company file
                  {
                      TsmNewPr.Visible = false;
                      TsmNewDb.Visible = false;
                      TsmNewCo.Enabled = true;
      
                      // arbitrary control if company file already exists. If exists, disable, otherwise enable.
                      #region TsmNewCo.Enabled (true/false)                               
      
                      selNodeParentName = TvwPanel.SelectedNode.Parent.Text;
                      selNodeName = TvwPanel.SelectedNode.Text;
      
                      Save_Treeview_To_Xml xcf = new Save_Treeview_To_Xml();
                      XElement xmlComplete = XElement.Load(xcf.xmlProfileComplete);
      
                      IEnumerable&lt;XElement&gt; profile =
                          from ep in xmlComplete.Elements(&quot;node&quot;)
                          where (string)ep.Attribute(&quot;text&quot;) == selNodeParentName
                          select ep;
      
                      foreach (XElement epi in profile)
                      {
                          IEnumerable&lt;XElement&gt; profNode =
                          from en in epi.Elements(&quot;node&quot;)
                          where (string)en.Attribute(&quot;text&quot;) == selNodeName
                          select en;
      
                          foreach (XElement enc in profNode)
                          {
                              // get the attribute texts
                              var childrenTexts = enc.Elements(&quot;node&quot;).Attributes(&quot;text&quot;);
      
                              foreach (var childText in childrenTexts)
                              {
                                  if (childText.Value != &quot;Company Name&quot; || childText.Value != &quot;File Path&quot;)
                                  {
                                      // enable TsmNewCo ContextMenu button if does not exists yet
                                      TsmNewCo.Enabled = false;
                                  }
                              }
      
                              // initialize the attribute tags to null
                              string CoFileTag = null;
                              string FilePathTag = null;
      
                              // get the attribute tags
                              var childrenTags = enc.Elements(&quot;node&quot;).Attributes(&quot;tag&quot;);
      
                              int count = 0;
                              // get db details for showing on the right panel of the main form specified below
                              foreach (var childTag in childrenTags)
                              {
                                  if (count == 0)
                                  {
                                      CoFileTag = childTag.Value;
                                  }
                                  else if (count == 1)
                                  {
                                      FilePathTag = childTag.Value;
                                  }
      
                                  count++;
                              }
      
                              // show db details on the right panel of the main form
                              if (CoFileTag != null || FilePathTag != null)
                              {
                                  TbcMain.SelectedIndex = 1;
                                  TbcMain.Visible = true;
                                  LblCompanyFileDef.Text = CoFileTag;
                                  LblFilePathDef.Text = FilePathTag;
                              }
                              else
                              {
                                  TbcMain.SelectedIndex = 1;
                                  TbcMain.Visible = false;
                              }
                          }
                      }
      
                      #endregion
      
                      TsmNewTk.Visible = false;
                      TsmNewTkCred.Visible = false;
                      TsmNewLg.Visible = false;
      
                      TsmEditPr.Visible = false;
                      TsmEditDb.Visible = false;
                      TsmEditCo.Enabled = true;
                      TsmEditTk.Visible = false;
                      TsmEditTkCred.Visible = false;
                      TsmEditLg.Visible = false;
      
                      TsmDeletePr.Visible = false;
                      TsmDeleteDb.Visible = false;
                      TsmDeleteCo.Enabled = true;
                      TsmDeleteTk.Visible = false;
                      TsmDeleteTkCred.Visible = false;
                      TsmDeleteLg.Visible = false;
      
                      TsmRunTk.Enabled = false;
                      TsmRefreshLg.Enabled = false;
                      TsmHelpAll.Enabled = true;
                  }
                  else if (Convert.ToString(e.Node.Tag) == &quot;d&quot;) //tasks
                  {
                      TsmNewPr.Visible = false;
                      TsmNewDb.Visible = false;
                      TsmNewCo.Visible = false;
                      TsmNewTk.Enabled = true;
      
                      #region Enable/Disable &quot;New&quot; if database and company file are not saved yet
      
                      selNodeParentName = TvwPanel.SelectedNode.Parent.Text;
                      selNodeDbSiblingName = TvwPanel.SelectedNode.PrevNode.PrevNode.Text;
                      selNodeCoSiblingName = TvwPanel.SelectedNode.PrevNode.Text;
      
                      Save_Treeview_To_Xml xcf = new Save_Treeview_To_Xml();
                      XElement xmlComplete = XElement.Load(xcf.xmlProfileComplete);
      
                      IEnumerable&lt;XElement&gt; profile =
                          from ep in xmlComplete.Elements(&quot;node&quot;)
                          where (string)ep.Attribute(&quot;text&quot;) == selNodeParentName
                          select ep;
      
                      // inquire if database has child or db already, if not this node is disabled
                      foreach (XElement epi in profile)
                      {
                          IEnumerable&lt;XElement&gt; profNode =
                          from en in epi.Elements(&quot;node&quot;)
                          where (string)en.Attribute(&quot;text&quot;) == selNodeDbSiblingName
                          select en;
      
                          if (profNode.Descendants().Count() == 0)
                          {
                              TsmNewTk.Enabled = false;
                          }
                      }
      
                      // inquire if company file has child or has file already, if not this node is disabled
                      foreach (XElement epi in profile)
                      {
                          IEnumerable&lt;XElement&gt; profNode =
                          from en in epi.Elements(&quot;node&quot;)
                          where (string)en.Attribute(&quot;text&quot;) == selNodeCoSiblingName
                          select en;
      
                          if (profNode.Descendants().Count() == 0)
                          {
                              TsmNewTk.Enabled = false;
                          }
                          else
                          {
                              foreach (XElement enc in profNode)
                              {
                                  // get the attribute tags
                                  var childrenTags = enc.Elements(&quot;node&quot;).Attributes(&quot;tag&quot;);
      
                                  int count = 0;
                                  // get company details for showing on the right panel of the main form specified below for task creation
                                  foreach (var childTag in childrenTags)
                                  {
                                      if (count == 1)
                                      {
                                          qbFilePath = childTag.Value;
                                      }
      
                                      count++;
                                  }
                              }
                          }
                      }
      
                      #endregion
      
                      TsmNewTkCred.Visible = false;
                      TsmNewLg.Visible = false;
      
                      TsmEditPr.Visible = false;
                      TsmEditDb.Visible = false;
                      TsmEditCo.Visible = false;
                      TsmEditTk.Enabled = false;
                      TsmEditTkCred.Visible = false;
                      TsmEditLg.Visible = false;
      
                      TsmDeletePr.Visible = false;
                      TsmDeleteDb.Visible = false;
                      TsmDeleteCo.Visible = false;
                      TsmDeleteTk.Enabled = false;
                      TsmDeleteTkCred.Visible = false;
                      TsmDeleteLg.Visible = false;
      
                      TsmRunTk.Enabled = false;
                      TsmRefreshLg.Enabled = false;
                      TsmHelpAll.Enabled = true;
      
                      // arbitrary control for showing up tasks summary
                      #region Extract data from Xml and show in the main form tabcontrol        
      
                      selNodeParentName = TvwPanel.SelectedNode.Parent.Text;
                      selNodeName = TvwPanel.SelectedNode.Text;
      
                      if (Xml_Extract_Data_TaskSum(selNodeParentName, selNodeName) == true)
                      {
                          TbcMain.SelectedIndex = 2;
                          TbcMain.Visible = true;
                      }
                      else
                      {
                          TbcMain.SelectedIndex = 2;
                          TbcMain.Visible = false;
                      }
      
                      #endregion
                  }                
                  else // for the task credentials
                  {
                      TsmNewPr.Visible = false;
                      TsmNewDb.Visible = false;
                      TsmNewCo.Visible = false;
                      TsmNewTk.Visible = false;
                      TsmNewTkCred.Enabled = false;
                      TsmNewLg.Visible = false;
      
                      TsmEditPr.Visible = false;
                      TsmEditDb.Visible = false;
                      TsmEditCo.Visible = false;
                      TsmEditTk.Visible = false;
                      TsmEditTkCred.Enabled = true;
                      TsmEditLg.Visible = false;
      
                      TsmDeletePr.Visible = false;
                      TsmDeleteDb.Visible = false;
                      TsmDeleteCo.Visible = false;
                      TsmDeleteTk.Visible = false;
                      TsmDeleteTkCred.Enabled = true;
                      TsmDeleteLg.Visible = false;
      
                      TsmRunTk.Enabled = true;
                      TsmRefreshLg.Enabled = false;
                      TsmHelpAll.Enabled = true;
      
                      // arbitrary control for showing up tasks details
                      #region Extract data from Xml and show in the main form tabcontrol                           
      
                      selNodeGrandParentName = TvwPanel.SelectedNode.Parent.Parent.Text;
                      selNodeDbSiblingName = TvwPanel.SelectedNode.Parent.PrevNode.PrevNode.Text;
                      selNodeCoSiblingName = TvwPanel.SelectedNode.Parent.PrevNode.Text;
                      selNodeParentName = TvwPanel.SelectedNode.Parent.Text;
                      selNodeName = TvwPanel.SelectedNode.Text;
      
                      Save_Treeview_To_Xml xcf = new Save_Treeview_To_Xml();
                      XElement xmlComplete = XElement.Load(xcf.xmlProfileComplete);
      
                      IEnumerable&lt;XElement&gt; profileTask =
                          from ep in xmlComplete.Elements(&quot;node&quot;)
                          where (string)ep.Attribute(&quot;text&quot;) == selNodeGrandParentName
                          select ep;
      
                      foreach (XElement ep in profileTask)
                      {
                          IEnumerable&lt;XElement&gt; profNodeTask =
                              from en in ep.Elements(&quot;node&quot;)
                              where (string)en.Attribute(&quot;text&quot;) == selNodeParentName
                              select en;
      
                          foreach (XElement ept in profNodeTask)
                          {
                              IEnumerable&lt;XElement&gt; profNodeTaskCred =
                                  from en in ept.Elements(&quot;node&quot;)
                                  where (string)en.Attribute(&quot;text&quot;) == selNodeName
                                  select en;
      
                              foreach (XElement eptc in profNodeTaskCred)
                              {
                                  // initialize the attribute tags to null
                                  string ActionTag = null;
                                  string TablesTag = null;
                                  string FiltersTag = null;
                                  string ScheduleTag = null;
      
                                  // get the attribute tags
                                  var childrenTags = eptc.Elements(&quot;node&quot;).Attributes(&quot;tag&quot;);
      
                                  int count = 0;
                                  // get db details for showing on the right panel of the main form specified below
                                  foreach (var childTag in childrenTags)
                                  {
                                      if (count == 0)
                                      {
                                          ActionTag = childTag.Value;
                                      }
                                      else if (count == 1)
                                      {
                                          TablesTag = childTag.Value;
                                      }
                                      else if (count == 2)
                                      {
                                          FiltersTag = childTag.Value;
                                      }
                                      else if (count == 3)
                                      {
                                          ScheduleTag = childTag.Value;
                                      }
      
                                      count++;
                                  }
      
                                  // show db details on the right panel of the main form
                                  if (ActionTag != null || FiltersTag != null || ScheduleTag != null)
                                  {
                                      LblActionDef.Text = ActionTag;
                                      // TablesTag
                                      string[] TablesTagArray = TablesTag.Split(','); //(new char[] { ',', ' ' });
                                      LvwTables.Items.Clear();
                                      foreach (string tt in TablesTagArray)
                                      {
                                          string table = tt.TrimStart();
                                          ListViewItem lvi = new ListViewItem(table);
                                          LvwTables.Items.Add(lvi);
                                      }
      
                                      // FiltersTag
                                      // filter period
                                      string filterPeriod;
                                      int Pos1 = FiltersTag.IndexOf(&quot;Transactions: &quot;) + &quot;Transactions: &quot;.Length;
                                      int Pos2 = FiltersTag.IndexOf(&quot; | Migration&quot;);
                                      filterPeriod = FiltersTag.Substring(Pos1, Pos2 - Pos1);
                                      LblFtrPeriodDef.Text = filterPeriod;
      
                                      // migration type
                                      string migrationType;
                                      int Pos3 = FiltersTag.IndexOf(&quot;Type: &quot;) + &quot;Type: &quot;.Length;
                                      int Pos4 = FiltersTag.IndexOf(&quot; | No&quot;);
                                      migrationType = FiltersTag.Substring(Pos3, Pos4 - Pos3);
                                      LblFtrMigTypeDef.Text = migrationType;
      
                                      // no of record per query
                                      string numberRecords;
                                      int Pos5 = FiltersTag.IndexOf(&quot;Query: &quot;) + &quot;Query: &quot;.Length;
                                      numberRecords = FiltersTag.Substring(Pos5);
                                      LblFtrRpqDef.Text = numberRecords;
      
                                      // filter head
                                      if (filterPeriod == &quot;All&quot; &amp;&amp; migrationType == &quot;Overwrite&quot; &amp;&amp; numberRecords == &quot;0&quot;)
                                      {
                                          LblFiltersDef.Text = &quot;Default&quot;;
                                      }
                                      else
                                      {
                                          LblFiltersDef.Text = &quot;Custom&quot;;
                                      }
      
                                      LblSchedDef.Text = ScheduleTag;
      
                                      TbcMain.SelectedIndex = 3;
                                      TbcMain.Visible = true;
                                  }
                                  else
                                  {
                                      TbcMain.SelectedIndex = 3;
                                      TbcMain.Visible = false;
                                  }
                              }
                          }
                      }
      
                      // capture the db credentials for task running                
                      Capture_DB_Credentials_for_NodeMouseClick_And_Task_Saving(selNodeGrandParentName, selNodeDbSiblingName, selNodeCoSiblingName);
      
                      #endregion
                  }
      
                  if (e.Button == MouseButtons.Right)
                  {
                      Point ClickPoint = new Point(e.X, e.Y);
                      TreeNode ClickNode = TvwPanel.GetNodeAt(ClickPoint);
                      if (ClickNode == null) return;
                      // Convert from Tree coordinates to Screen coordinates    
                      Point ScreenPoint = TvwPanel.PointToScreen(ClickPoint);
                      // Convert from Screen coordinates to Form coordinates    
                      Point FormPoint = this.PointToClient(ScreenPoint);
                      CmsPanel.Show(this, FormPoint);
                  }
              }
  </code></pre>