Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a DataGrid on a WPF UserControl with a CheckBox column. The DataGrid is bound to an ObservableCollection in the UserControl's ViewModel. I also have a SelectedItem property in the UserControl's ViewModel to which the SelectedItem property of the DataGrid is bound.

What I'm attempting to achieve is when you select a row of the DataGrid, the CheckBox get checked (and obviously the SelectedItem is updated in the ViewModel). If you then click on the same selected row a second time, the CheckBox should become unchecked, but the selected row must not be set to null. (so Ctrl+Click is not going to work for me)

How can I get the DataGrid to realise that I have "selected" a row which is already selected?

I hope someone has a solution for me!

Thanks!
Posted
Updated 18-Jan-12 20:52pm
v2

Never mind. Managed to solve this on my own.

If you want to know how, ask me, albeit the solution I ended up using is a bit different to the solution i was looking for.
 
Share this answer
 
Comments
govardhan4u 25-May-12 2:31am    
can you let me know how did you solve it?
Theoretically this should be fairly easy to achieve based purely on the use of the property you have bound to for IsSelected. What I would do is include a check like this:
C#
public bool IsSelected
{
  get { return isSelected; }
  set
  {
    if (isSelected || isSelected != value) return;
    isSelected = value;
    OnChanged("IsSelected");
  }
}
By including the check to see if isSelected is already true for this row, we can ensure that we don't try to update the row if we have already set it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900