DataGrid.SelectedCellsChanged 이벤트

정의

SelectedCells 컬렉션이 변경될 때 발생합니다.Occurs when the SelectedCells collection changes.

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 

이벤트 유형

SelectedCellsChangedEventHandler

예제

다음 예제에서는 이벤트를 처리 하 SelectedCellsChanged 고 새로 선택한 셀의 값을 지우는 방법을 보여 줍니다.The following example shows how to handle the SelectedCellsChanged event and clear the values in the newly selected cells.

<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

설명

SelectedCellsChanged선택한 셀의 컬렉션이 변경 될 때 알리도록 이벤트를 처리할 수 있습니다.You can handle the SelectedCellsChanged event to be notified when the collection of selected cells is changed. 선택 영역에 전체 행이 포함 된 경우에 Selector.SelectionChanged 도 이벤트가 발생 합니다.If the selection includes full rows, the Selector.SelectionChanged event is also raised.

AddedCells RemovedCells 이벤트 처리기의에서 및를 검색할 수 있습니다 SelectedCellsChangedEventArgs .You can retrieve the AddedCells and RemovedCells from the SelectedCellsChangedEventArgs in the event handler.

적용 대상

추가 정보