Take the 2-minute tour ×

So I have a WPF application and a datagrid in it, uneditable, with full row selecting enabled, and I'm trying to make a kind of toggle on-off functionality with the datagrid rows. However, I can't seem to find the appropriate Event for a simple row selection. There's SelectionChanged, which doesn't work if I click again on the already selected item. There's simple Click (many types of them), but all of them happen BEFORE the row is actually selected, so if I try to get selected item on the click I will get null. There is some other Event (that I forgot about) that requires to click twice, which is not really what I want. I'm running out of ideas, maybe there's some good event-combination or some way to override them or maybe I'm just missing something?

share|improve this question
Please don't prefix your titles with "C#" and such. That's what the tags are for. –  John Saunders May 15 '12 at 20:03
add comment

3 Answers

up vote 2 down vote accepted

Considering the information you have given, @Yatrix's solution is perfectly valid!

But to that you have responded ..

Happens before the row is selected, so doesn't work :/

Then there is something you are missing here. Even if LeftMouseDown \ LeftMouseUp \ PreviewLeftMouseDown \ Up events occur before selection event, they would know if the row is already selected or not. That way they can deselect it and then do


.... so that selection is never called after mouse events thus the reselection is avoided.

Try and let me know.

share|improve this answer
add comment

PreviewMouseDown or PreviewMouseLeftButtonDown may help. I also found this on this site that may provide you with direction:

How can I get a DataGrid to unselect on click when SelectionMode="Extended"?

share|improve this answer
Happens before the row is selected, so doesn't work :/ –  Ernestas Romeika May 15 '12 at 20:16
add comment

If you want to sign up for the row Selected event you'll need to do it for each row in the DataGrid. Try signing up for the LoadingRow event on the DataGrid and for each row sign up for the Selected event.

share|improve this answer
add comment

Your Answer


