2011-01-17 30 views
6

私はWPFツールキットのデータグリッドを使用しています。 SelectionUnit = "Cell"SelectionMode = "Extended"に設定しました。WPF Datagrid:SelectionUnit = "Cell"のときにSelectionChangedイベントが発生しない

SelectionChangedイベントは発生しません。

SelectionUnitがFullRowに設定されているとうまく動作します。

私は何かありませんか?

私が必要とする理由は、SelectedCellを私のViewModelにバインドするのに役立つ添付プロパティを作成しようとしているからです。

答えて

7

DataGrid.SelectedCellsChangedprovide youに必要なものを使用してください。

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(); 

    } 
} 
+0

アーロンの権利。 SelectionChangedは実際に動作し、必要な情報を提供します。 – GuYsH

関連する問題