Hi,
I have a context menu on my XamGrid. I need to get the underlying rows datacontext when I click on a context menu item. For that I guess I would first need to set the row as selected on right clicking on a row. How do I achieve this? Please note that I'm asking for a solution for XamGrid and not XamDataGrid.
Thanks.
Ganesh
Hello Ganesh,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Hi Stefan, I am also having trouble to do the right click on XAMGRID, not XAMDATAGRID.
My view is:
<ig:XamGrid
Name="xamRaceDetails" Margin="5,0,0,0" Grid.Row="3" ActiveItem="{Binding SelectedDec, Mode=TwoWay}" ItemsSource="{Binding Decisions}" AutoGenerateColumns="False" Grid.Column="0" Grid.ColumnSpan="5" >
and here is some ContextMenu
<ig:XamGrid.ContextMenu > <ContextMenu > <MenuItem Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=DataContext.SaveFavoriteCommand}" Header="Save As Favorite Race" /> <MenuItem Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=DataContext.RemoveFavoriteCommand}" Header="Remove Favorite Race" /> </ContextMenu> </ig:XamGrid.ContextMenu>
I want to make the right click--> choose from the ContextMenu and fire the command. Right now it seems I have to LEFT click it first and then right click to pass in database, otherwise simply RIGHT click on cell will not make the ActiveItem change.
this has confused me for two days and there are very limited posts related to XAMGRID. Please attach a simple solution if possible.
Thanks,
David
To Select the Row the following was implemented.
private static void MainXamGridPreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var cell = Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(CellControl), true) as CellControl; var xamGrid = sender as XamGrid; if (cell == null || xamGrid == null) { return; }
xamGrid.Rows[cell.Cell.Row.Index].IsSelected = true; }
Yes,This is a good approach for every one in this plate form.I think this is a good informatic place.Thanks for sharing this information.
Hello David,
I can suggest you handle the XamGrid's PreviewMouseRightButtonDown event and add the following code in its handler:
CellControl cell = Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(CellControl), true) as CellControl; (sender as XamGrid).ActiveItem = cell.Cell.Row.Data;
in order to make the clicked row active.
Hope this helps you.