The WPF Datagrid: SelectionChanged event does not occur when SelectionUnit = "Cell"

I am using the WPA tooltit datagrid. I have set SelectionUnit = "Cell" and SelectionMode = "Extended" .

The SelectionChanged event never rises!

It works great if the SelectionUnit parameter is set to FullRow.

Did I miss something?

By the way, the reason I need this is because I'm trying to create an Attached Property to help me associate SelectedCells with my ViewModel.

+6
wpf datagrid wpfdatagrid
source share
1 answer

Use DataGrid.SelectedCellsChanged , which should provide you with what you need.

 private void DG1_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { //Get the newly selected cells IList<DataGridCellInfo> selectedcells = e.AddedCells; //Get the value of each newly selected cell foreach (DataGridCellInfo di in selectedcells) { //Cast the DataGridCellInfo.Item to the source object type //In this case the ItemsSource is a DataTable and individual items are DataRows DataRowView dvr = (DataRowView)di.Item; //Clear values for all newly selected cells AdventureWorksLT2008DataSet.CustomerRow cr = (AdventureWorksLT2008DataSet.CustomerRow)dvr.Row; cr.BeginEdit(); cr.SetField(di.Column.DisplayIndex, ""); cr.EndEdit(); } } 
+7
source share

All Articles