This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
When a right click occurs in the DataGrid how can I tell what cell (and row/column) was clicked? MouseRightButtonUp source seems to just give the DataGrid as both the Source and OriginalSource of the event. For comparison, the Microsoft DataGrid gives the element within the visual tree that was clicked and I can find the cell that was clicked using VisualTreeHelper. I'm not sure why this would work differently for the Mindscape DataGrid since I thought this was just standard WPF event processing. Peter |
|
|
Hello Peter This is just standard WPF event processing, so I'm not sure why the OriginalSource is giving you the DataGrid. At my end the OriginalSource is a TextBlock which I can then use to follow the visual tree and get the DataGridCellContainer. I did this by attaching a handler to the DataGrid like this:
If it is still not working, you could use Mouse.DirectlyOver to start looking through the visual tree, or send more details that I could use to reproduce your scenario at my end. Jason Fauchelle |
|
|
Hi Jason, I have been using MouseRightButtonUp instead of MouseRightButtonDown. When I switched to MouseRightButtonDown it worked as expected (returns the TextBlock as original source). However, shouldn't these work the same? Please let me know what you get using MouseRightButtonUp (in case you don't see what I am seeing I am submitting another post with a demo project that shows this problem as well). I have read advice that it is better to use MouseRightButtonUp for displaying popup menus, though I don't remember why. Peter |
|
|
Hello Peter I can reproduce this at my end with MouseRightButtonUpEvent. I'll look into this soon. |
|
|
Hello Peter I have not been able to determine the cause of the OriginalSource being the DataGrid. We aren't doing much in terms of handling the mouse button up events. In any case, you can use the static Mouse.DirectlyOver property to get the element the mouse is over and hack through the visual tree that way. Jason Fauchelle |
|
|
Hi Jason, Thanks. I tried using the MouseRightButtonDown event and it seems to also give an acceptable work-around. If I run into any problems with that I will try the Mouse.DirectlyOver, but I would think that if the mouse is moving quickly it might give a different location (probably not much of a problem, if any). Peter |
|