0

In my WPF DataGrid there is short list of phone numbers for a contact. I want to allow ONLY ONE of the numbers to be marked as preferred.

The view model has a property for the contact (an entity from the database) and an ObservableCollection of related PhoneNumbers, also from the database. Simplified PhoneNumbers entity looks like this:

    class PhoneNumbers
{
    [Key]
    public int ID { get; set; }
    public string PhoneNbr { get; set; }
    public bool Preferred { get; set; }
    public int ContactID { get; set; }
}

The DataGrid displays the PhoneNbr property in a DataGridTextColumn and the Preferred property in a DataGridCheckBoxColumn; the other properties aren't displayed.

In an ideal world, when the user checks a phone number in the DataGrid, all the other numbers would automatically be UNCHECKED. Right now I have no control over this - they're free to check any or all of them.

So...I'm looking for guidance in how to make this happen. Thanks

TWDuke
  • 53
  • 5
  • 1
    You should have a read of [this](http://stackoverflow.com/questions/10409744/control-radiobutton-datagridtemplatecolumn-from-code) – Bob. Mar 03 '14 at 18:03
  • Sorry if I'm dense, but I don't see the relevance. Did I misread it? That appears to refer to the enabling of controls in a column where I'm looking for a way to hook the changed value of an EF entity's property so I can change the OTHER entities in the grid. – TWDuke Mar 03 '14 at 18:18
  • 1
    Sorry, I was referring to the use of `RadioButton` `DataTemplate` instead of using a `DataGridCheckBoxColumn` since the point of having a `CheckBox` is to allow multiple selections, whereas the `RadioButton` (assuming you set the `GroupName` property to be the same`) only allows selection of one. – Bob. Mar 03 '14 at 18:32
  • Interesting and intriguing. I'll have to look at that in a new light. Thanks for the clarification – TWDuke Mar 03 '14 at 18:56
  • Bob - Try as I might, there's no progress on this using the radiobutton template. I've got the visual portion working, but the property change isn't firing for any of the entities. I mean that the display allows only one row to show as Preferred, but the Preferred property - to which IsChecked is bound - isn't updating for any of the rows. – TWDuke Mar 03 '14 at 23:21
  • You need to implement `INotifyPropertyChanged` for your `PhoneNumbers` object. – Bob. Mar 04 '14 at 12:30
  • I'm using EF 5 and created the model from the database, so it does implement it, that's why I'm stumped – TWDuke Mar 04 '14 at 15:35

0 Answers0