Search code examples
wpfeventsrouted-events

How to detect a click on the selected row of a RadGridView control


My WPF application uses the Telerik RadGridView control on a few of its screens. I have a requirement that says that whenever the user clicks on a row in the RadGridView, I'm supposed to switch to another screen and display detail information about that row. I hooked up a handler to the SelectionChanged event and this works, except that nothing happens if the user clicks on the selected row a second time. This makes sense, as the selected row isn't being changed.

How can I detect a second click on the same row and have the second screen displayed?

Tony


Solution

  • You could just attach a handler to the MouseUp event on the GridView. Check if there are any selected cells and respond from there. This will fire even if there is already a selection.

    The MouseDown event will fire on the mouse click, but before the gridview updates the selction, mouse up should fire when the selection has already been adjusted

    You can also attach a handler to each individual cell in code-behind as follows

    (this.GridView as RadGridView).AddHandler(  
         GridViewCell.MouseUpEvent,  
         new EventHandler<Telerik.Windows.RadRoutedEventArgs>(this.OnMouseUp));