ContextMenu & which cell was clicked ?...

2 posts, 0 answers
  1. Paul
    Paul avatar
    24 posts
    Member since:
    Jul 2010

    Posted 12 Aug 2011 Link to this post


    We are using a context menu on a RadTreeListView component.
    This menu must show different options depending upon which cell or column etc... was right-clicked.

    The trouble is that, the following code returns the columnIndex of the cell that currently has the focus, NOT the one that was right-clicked as this cell does not recieve the focus  prior to the right-click & context menu being shown.



    int columnIndex = ((GridViewDataControl)(((RadContextMenu)(e.Source)).UIElement)).CurrentColumn.DisplayIndex;


    is there any way to determine the cell, and/or column and/or data item for the "point" where the mouse was right-clicked ?...

    We can only do manual interception of righ-clicks if there is no context menu defined - if we apply a context menu (which we prefer) then the right-click handler will not fire in our code-behind.

    Is there any way to do this please ?...

    Thanks - Paul.
  2. Maya
    Maya avatar
    4062 posts

    Posted 15 Aug 2011 Link to this post

    Hi Paul,

    You may handle the Opening event of the RadContextMenu and find the underlying cell through the GetClickedElement<T>() method:

    private void RadContextMenu_Opening(object sender, Telerik.Windows.RadRoutedEventArgs e)
                RadContextMenu menu = (RadContextMenu)sender;
                GridViewCell clickedCell = menu.GetClickedElement<GridViewCell>();
                if (clickedCell != null)
                    var columnIndex = clickedCell.Column.DisplayIndex;         

    Thus depending on the column index, you may perform the logic you require. 

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top