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
Any ideas?
Are you trying to pass a record from the first grid to the BringIntoView(...) method of the second one?
Please note that you can only request a record to be brought into view of the same grid that the method is being called for.
The code I have is the following
void DRP_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { DataRecordPresenter drp = sender as DataRecordPresenter;
if ( drp != null ) SelectedItems.Records.Add( drp.Record );
}
This is what is failing.
cheers
Any Ideas?
This is failing, because of this line :
if ( drp != null )
SelectedItems.Records.Add( drp.Record );
Where is this SelectedItems.Records defined? This is a property of the XamDataGrid, but you are using it in a different context. Is it possible to provide a sample project so that we can look into it?
What is the ultimate goal that you want to achieve?
This isn't the issue i'm having -
If you run the attached project you'll see that the select row count is wrong when right clicking on additional rows - so with one row selected, right clicking on a different row will print out '1' to the project output when it should be 2.
I see where the problem is. The SelectionChanged event will fire for all the types of objects that can be selected in the XamdataGrid - Cells, Fields, Records. So, what you need to do is check the e.Type property and see which type is being selected:
if (e.Type == typeof(Record))
it looks like the SelectionChanged event is fired but the SelectedItems collection doesn't contain the correct count of rows.
I have attached a sample showing this
I'm an idiot.. sorry.
I didn't twig that
EventManager.RegisterClassHandler( typeof( DataRecordPresenter ), PreviewMouseRightButtonDownEvent,
new MouseButtonEventHandler( onMouseRightButtonDown ) );
is a global registration ....
silly me :)
thanks!