OnContextMenuOpening - how to find cell?

Jul 6, 2009 at 2:20 PM
how to find cell related to ContextMenuEventArgs? (if there is any cell related)
my try with
            Microsoft::Windows::Controls::DataGridCell^ cell = WpfGuiHelpers::FindParent<Microsoft::Windows::Controls::DataGridCell>((Visual^)e->OriginalSource);
fails because OriginalSource (sometimes?) has no Parent (!? how it is possible?)
maybe i can use this->CurrentCell but i'm not sure it is always correct one
thanks for reply
my source part:
void XGridControl::OnContextMenuOpening(ContextMenuEventArgs^ e)
{
    __super::OnContextMenuOpening(e);
    Microsoft::Windows::Controls::Primitives::DataGridColumnHeadersPresenter^ hdr
        = WpfGuiHelpers::FindVisualChild<Microsoft::Windows::Controls::Primitives::DataGridColumnHeadersPresenter>(this);
    if(hdr)
    {
        GeneralTransform^ pTransfWpfElementToWindow = hdr->TransformToAncestor( this );
        Point offsetPoint = pTransfWpfElementToWindow->Transform( Point(0, 0) );
        GeneralTransform^ pTransfWpfElementToWindow2 = ((Visual^)e->OriginalSource)->TransformToAncestor( this );
        Point cursorPoint = pTransfWpfElementToWindow2->Transform( Point(e->CursorLeft, e->CursorTop) );
        if(e->CursorLeft != -1
            && e->CursorTop != -1
            && offsetPoint.X <= cursorPoint.X
            && cursorPoint.X <= (offsetPoint.X + hdr->ActualWidth)
            && offsetPoint.Y <= cursorPoint.Y
            && cursorPoint.Y <= (offsetPoint.Y + hdr->ActualHeight)
            )
        {
//header
...
        }
        else
        {  
//maybe cell
            Microsoft::Windows::Controls::DataGridCell^ cell = WpfGuiHelpers::FindParent<Microsoft::Windows::Controls::DataGridCell>((Visual^)e->OriginalSource);
            if(cell)
            {
...
            }
        }
    }
}