this.datagrid.ItemsSourceChanged += datagrid_ItemsSourceChanged; void datagrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e) { if(datagrid.View!=null) this.datagrid.View.RecordPropertyChanged += View_RecordPropertyChanged; } void View_RecordPropertyChanged(object sender, PropertyChangedEventArgs e) { var model = sender as BusinessObjects; var viewModel = this.datagrid.DataContext as ViewModel;
if(e.PropertyName=="IsChecked") { if (model.IsChecked) viewModel.CheckedItems.Add(model.EmployeeName.ToString()); else viewModel.CheckedItems.Remove(model.EmployeeName.ToString()); } |
this.datagrid.CurrentCellValueChanged += datagrid_CurrentCellValueChanged; void datagrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs args) { var viewModel=this.datagrid.DataContext as ViewModel; if ((args.Record as BusinessObjects).IsChecked) viewModel.CheckedItems.Add((args.Record as BusinessObjects).EmployeeName); |