You seem to view this issue from a WinForms perspective. In WPF, we usually prefer to manipulate data objects rather than user interface objects. You said that you do not have an ObservableCollection<T> for your products, but I would recommend that you use it.
If you don't have a data type class for your data, I would advise you to create one. Then you must implement the INotifyPropertyChanged interface.
After that and setting your collection property as the ItemsSource your DataGrid , all you need to do is bind the INotifyPropertyChanged handler to the selected data type:
In the view model:
public ObservableCollection<YourDataType> Items { get { return items; } set { items = value; NotifyPropertyChanged("Items"); } } public YourDataType SelectedItem { get { return selectedItem; } set { selectedItem = value; NotifyPropertyChanged("SelectedItem"); } }
In the view model constructor:
SelectedItem.PropertyChanged += SelectedItem_PropertyChanged;
In the view model:
private void SelectedItem_PropertyChanged(object sender, PropertyChangedEventArgs e) { // this will be called when any property value of the SelectedItem object changes if (e.PropertyName == "YourPropertyName") DoSomethingHere(); else if (e.PropertyName == "OtherPropertyName") DoSomethingElse(); }
In the user interface:
<DataGrid ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" ... />
Sheridan
source share