title: How to resolve conflicts between Derived Custom Control Class and EventHandlers in Form1.cs
body: <pre><code>public class CustomListView : ListView
  {
      public CustomListView()
      {
  
      }
      private bool ContextAllowed = false;
  
      public override ContextMenuStrip ContextMenuStrip
      {
          get
          {
              return base.ContextMenuStrip;
          }
          set
          {
              base.ContextMenuStrip = value;
              base.ContextMenuStrip.Opening += ContextMenuStrip_Open;
          }
      }
  
      protected override void OnMouseDown(MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Right)
          {
              ListViewHitTestInfo test = HitTest(e.X, e.Y); //perform a hit test
              if (test.Item != null) //if it hits an item, display the popup bar
              {
                  ContextAllowed = true;
              }
          }
          base.OnMouseDown(e);
      }
      protected override void OnMouseUp(MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Right)
          {
              ContextAllowed = false; //close the menu
          }
          base.OnMouseUp(e);
      }
  
      private void ContextMenuStrip_Open(object sender, CancelEventArgs e)
      {
          if (!ContextAllowed)
          {
              e.Cancel = true;
          }
      }
  }
  </code></pre>
  
  <p><strong>The Problem:</strong>
  The above code is for a class called CustomListView. It is a custom control, whose purpose is to allow me to right-click a row and perform functions with that row. I succesfully built it as a dll, added it to the toolbox, and am using it on my form. I am able to fill it with info just like a regular ListView, but ANY right-click functionality with the ContextMenuStrip is just not working. </p>
  
  <p><strong>Attempts at Solutions:</strong>
  I HAVE assigned the ContextMenuStrip to the CustomListView control. I think the problem is the EventHandlers in the CustomListView class (i.e. the OnMouseDown and OnMouseUp) are not being used. Instead, the "other" event handers with the same name are being used in Form1.cs, that naturally contain no code.</p>
  
  <p>Should I move the EventHandlers in the CustomListView class to Form1.cs? How can I get the EventHandlers in the CustomListView class to be used?</p>