I have set a contextmenu on the grid and am changing the state of various items in that menu in response to the selection changing on the grid. All works as expected if i first left click on a row before right clicking on it (in that the context menu is correctly based on the currently selected row), however if i right click on an unselected row, selection doesn't change and as such i don't get a correct context menu.
How do i get the grid to change selection on right click ?
Hello,
You may find this blog post and its sample helpful.
http://blogs.infragistics.com/blogs/alex_fidanov/archive/2009/07/22/contextmenus-tooltips-mouse-clicks-amp-utilities.aspx
Slight problem with the solution suggested - the grid seems to be removing selection on other rows when i do the following
. Highlight multiple rows. right click on the last row ( perform the right click on all the rows on the selection)
On the right click, all previous rows are unselected. Why is this? Also, if the user right clicks a row, then moves to another row (without dismissing the context menu) then multiple rows are selected with each right click... very strange behaviour.
How do i keep the selections for the right click menu ?
regards
perfect - so in summary, one would register for the DataRecordPresenter's PreviewMouseRightButtonDownEvent and force the record to be selected
EventManager.RegisterClassHandler(typeof(DataRecordPresenter), DataRecordPresenter.PreviewMouseRightButtonDownEvent, new MouseButtonEventHandler(DRP_MouseRightButtonDown));
void DRP_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
DataRecordPresenter drp = sender as DataRecordPresenter;
if ( drp != null ) drp.IsSelected = true;
}