DataGrid.SelectedCellsChanged Evento
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Si verifica quando l'insieme SelectedCells viene modificato.
public:
event System::Windows::Controls::SelectedCellsChangedEventHandler ^ SelectedCellsChanged;
public event System.Windows.Controls.SelectedCellsChangedEventHandler SelectedCellsChanged;
member this.SelectedCellsChanged : System.Windows.Controls.SelectedCellsChangedEventHandler
Public Custom Event SelectedCellsChanged As SelectedCellsChangedEventHandler
Public Event SelectedCellsChanged As SelectedCellsChangedEventHandler
Tipo evento
Esempio
Nell'esempio seguente viene illustrato come gestire l'evento SelectedCellsChanged e cancellare i valori nelle celle appena selezionate.
<Grid>
<DataGrid Name="DG1" ItemsSource="{Binding}" SelectionUnit="CellOrRowHeader" SelectionChanged="DG1_SelectionChanged" SelectedCellsChanged="DG1_SelectedCellsChanged" />
</Grid>
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();
}
}
Private Sub DG1_SelectedCellsChanged(sender As Object, e As SelectedCellsChangedEventArgs)
'Get the newly selected cells
Dim selectedcells As IList(Of DataGridCellInfo) = e.AddedCells
'Get the value of each newly selected cell
For Each di As DataGridCellInfo In selectedcells
'Cast the DataGridCellInfo.Item to the source object type
'In this case the ItemsSource is a DataTable and individual items are DataRows
Dim dvr As DataRowView = DirectCast(di.Item, DataRowView)
'Clear values for all newly selected cells
Dim cr As AdventureWorksLT2008DataSet.CustomerRow = DirectCast(dvr.Row, AdventureWorksLT2008DataSet.CustomerRow)
cr.BeginEdit()
cr.SetField(di.Column.DisplayIndex, "")
cr.EndEdit()
Next
End Sub
Commenti
È possibile gestire l'evento SelectedCellsChanged da notificare quando viene modificata la raccolta di celle selezionate. Se la selezione include righe complete, viene generato anche l'evento Selector.SelectionChanged .
È possibile recuperare e AddedCellsRemovedCells dal SelectedCellsChangedEventArgs gestore eventi.