Context menu only on Row/Column Headers

Posted by: droopy5 on 8 September 2017, 1:22 pm EST

  • Posted 8 September 2017, 1:22 pm EST

    Hi..


        Iam using a context menu which has to appear when i right-click on only column headers and row headers.


      For columns,it has the items as 'Add column'.'Remove column'


      For rows,it has the items as 'Add row'.'Remove row'


    It must work exactly like an Excel sheet..like .adding a row/column wherever the user points to, within a specified set of columns or rows.


    the code below doesnt work under this cell click event.It appears only on form_load event.


    private void fpSpread2_CellClick(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)


    {


    if (e.Row.Equals(0))


    {


    }


    }


    ""MenuItem mi = new MenuItem("Remove Selection");


    mi.Click += new EventHandler(mi_Click);


    ContextMenu cm = new ContextMenu();


    cm.MenuItems.Add(mi);


    fpSpread2.ContextMenu = cm; ""


     


    the event 'mi_Click' that is called here also doesnt work.I want the row/column to be added only at the specific position the user clicks.


    This event doesnt accept e.Column or e.Row.


     


    Can somebody help me with this.I have been browsing a lot for this code but in vain.


    Am using C# code


     


    Thanks


    Droopy

  • Replied 8 September 2017, 1:22 pm EST

    Droopy -

    In the CellClick event you need to check if you are clicking on a column or row header and if it returns true then you can show your context menu.

  • Replied 8 September 2017, 1:22 pm EST

    Hi Bob


      I tried giving it as


    if(e.row.equals(-1))


    {


    }


    but doesnt work.Anywhere i click on the sheet,i get my context menu displayed.Can u please halp me with the coding as i havnt been able to proceed further.How do i add/delete only the selected row/column??


     

  • Replied 8 September 2017, 1:22 pm EST

    Hi Bob


    I wrote my code like this


    private void fpSpread2_CellClick(object sender, CellClickEventArgs e)


    {


    //contextMenuStrip2.Visible = false;


    if(e.ColumnHeader==true)


    {


    e.Cancel = true;


    //context menu


    MenuItem mi = new MenuItem("Add Columns");


    MenuItem mi1 = new MenuItem("Delete Columns");


    mi.Click += new EventHandler(mi_Click);


    ContextMenu cm = new ContextMenu();


    cm.MenuItems.Add(mi);


    cm.MenuItems.Add(mi1);


    fpSpread2.ContextMenu = cm;


    //contextMenuStrip2.Visible = true;


     


    }


     


    Inspite of this,the context menu appears everywhr on the sheet.Please help me out.


    Thanks


    Droopy

  • Replied 8 September 2017, 1:22 pm EST

    Private Sub FpSpread1_CellClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles FpSpread1.CellClick
    Dim mi As New MenuItem("Remove")
    Dim cm As New ContextMenu
    cm.MenuItems.Add(mi)

    If e.ColumnHeader = True Then
    FpSpread1.ContextMenu = cm
    Else
    FpSpread1.ContextMenu = Nothing
    End If
    End Sub
  • Replied 8 September 2017, 1:22 pm EST

    Thanks Bob


      It works perfectly fine..:-)

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels