I need to hook on to the "click event" when the selected row in the grid is clicked(once)
5 Answers, 1 is accepted
You may subscribe to the SelectionChanging/SelectionChanged event of RadGridView to achieve the desired result. Please refer to our online documentation for further info.
If you need any further assistance do not hesitate to contact us!
Vanya Pavlova
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Seems like the SelectionChanging/SelectionChanged event is triggered when you fill the grid with data or when you edit on one of the rows.
If I click on the selected row (after the grid is populated and one row already is selected) none of these events are triggered.
When the SelectionUnit is set to FullRow, the e SelectionChanged event is fired first and after that the CurrentCellChanged event fires as it was described in our docs.
You may also write some custom code for such purpose (without going in edit mode) - through subscribing to the RadGridView's RowLoaded event and attach to the MouseLeftButtonDown of a GridViewRow:
private
void
RadGridView_RowLoaded(
object
sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
var row = e.Row
as
GridViewRow;
if
(row !=
null
)
{
this
.AddHandler(GridViewRow.MouseLeftButtonDownEvent,
new
MouseButtonEventHandler(GridViewRow_MouseLeftButtonDown),
true
);
}
}
private
void
GridViewRow_MouseLeftButtonDown(
object
sender, MouseButtonEventArgs e)
{
MessageBox.Show(
"Hi"
);
}
Kind regards,
Vanya Pavlova
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
To completing your answer/workaround to get the row clicked event I would change only one small detail on the code you posted. Where you wrote 'this.AddHandler...' must be 'row.AddHandler...' because of if you have more than one RadGridView into the same control/window. If not, you will receive the clicked event for all rows of all RadGridViews you have into the control/window where the required one is located.
It's only a small detail that had made me think for a while :)
Best regards,
Antonio Jesús.