Home Forums WinForms controls Xceed Grid for WinForms Context menu strip Reply To: Context menu strip

User (Old forums)
Member
Post count: 23064

You can set the ShowFocusRectangle property on the GridControl to false, which will permit you to enable CellNavigation.

Then you can add an event handler for the MouseDown of the ColumnManagerCell’s, and add a verification on the type of cell that is current in the handler.  Note that if you have other types of rows in the grid that can have the current cell set on it (e.g. InsertionRow), you will need to subscribe to the same MouseDown event on it.

e.g.:

    private void Form1_Load( object sender, EventArgs e )
    {
      gridControl1.ReadOnly = true;
      gridControl1.ShowFocusRectangle = false;
      gridControl1.ContextMenuStrip = contextMenuStrip1;
      contextMenuStrip1.Opening += new CancelEventHandler( contextMenuStrip1_Opening );

      foreach( Cell cell in dataRowTemplate1.Cells )
      {
        cell.MouseDown += new MouseEventHandler(cell_MouseDown);
      }

      foreach( ColumnManagerCell cell in columnManagerRow1.Cells )
      {
        cell.MouseDown += new MouseEventHandler(cell_MouseDown);
      }

    }

    private bool onCurrentCell = false;

    void cell_MouseDown( object sender, MouseEventArgs e )
    {
      Cell cell = sender as Cell;
      if( cell != null && cell.IsCurrent && cell.GetType() == typeof( DataCell ) )
      {
        onCurrentCell = true;
      }
      else
      {
        onCurrentCell = false;
      }
    }

    void contextMenuStrip1_Opening( object sender, CancelEventArgs e )
    {
      if( !onCurrentCell )
      {
        e.Cancel = true;
      }
        onCurrentCell = false;
    }

Imported from legacy forums. Posted by André (had 2219 views)