This is a migrated thread and some comments may be shown as answers.

ContextMenu & which cell was clicked ?...

1 Answer 83 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 12 Aug 2011, 08:37 AM
Hi,

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.

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Aug 2011, 10:04 AM
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,
Maya
the Telerik team

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

Tags
TreeListView
Asked by
Paul
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or