Does anyone know how to access the data record (e.g. Business object) supplying a row in a XamDataGrid from a context menu on the grid?
Here's what I'm doing.
I am programatically adding a Context Menu to the Grid:
MenuItem sellItem = new MenuItem();
xamDataGrid1.ContextMenu.Items.Add(sellItem);
Then in the click event, I have tried numerous ways to access the data in the current row, one of those ways being the same way that other developers in our shop have accessed the data behind a row in the double click event. (see below)
(this works just fine):
DependencyObject source = e.OriginalSource as DependencyObject;
if (source != null){
CellValuePresenter cvp = Infragistics.Windows.Utilities.GetAncestorFromType(source, typeof(CellValuePresenter), true) as CellValuePresenter;
if (cvp != null){
someObject = ((<businessObject>)(((DataItemPresenter)(cvp)).Record.DataItem)).ProductKey;
...
}
Anyone got any ideas?
Thanks,
Damian
Followup: I've tried numerous variations of the code in the above double click event to access the current selected row from the context menu click event, but have not been able to successfully do so (unlike doing it in the double click event, which accesses the row data without a problem).