DataGrid.SelectedCells 屬性


取得目前選取之儲存格的清單。Gets the list of cells that are currently selected.

 property System::Collections::Generic::IList<System::Windows::Controls::DataGridCellInfo> ^ SelectedCells { System::Collections::Generic::IList<System::Windows::Controls::DataGridCellInfo> ^ get(); };
public System.Collections.Generic.IList<System.Windows.Controls.DataGridCellInfo> SelectedCells { get; }
member this.SelectedCells : System.Collections.Generic.IList<System.Windows.Controls.DataGridCellInfo>
Public ReadOnly Property SelectedCells As IList(Of DataGridCellInfo)



目前選取之儲存格的清單。The list of cells that are currently selected.


有三種選取模式 DataGridThere are three selection modes for DataGrid. 選取模式會與屬性一起設定 SelectionUnitThe selection mode is set with the SelectionUnit property. 根據 SelectionUnitSelectedCellsSelectedItems 將包含下表中所定義之選取專案的集合。Depending on the SelectionUnit, SelectedCells or SelectedItems will contain a collection of selected items as defined in the following table.

DataGridSelectionUnitDataGridSelectionUnit value SelectedCellsSelectedCells value SelectedItemsSelectedItems value
Cell 選定儲存格的集合Collection of selected cells 空白Empty
FullRow 所選資料列中的資料格集合Collection of cells in the selected rows 選取的資料列集合Collection of selected rows
CellOrRowHeader 選取之資料格的集合,包括選取的資料列中的所有資料格Collection of selected cells, including all cells in a selected row 如果未選取完整的資料列,則為選取的資料列集合或空白Collection of selected rows or empty if no full rows are selected

當選取資料格時, DataGridCell.Selected 就會引發事件、將 DataGridCell.IsSelected 屬性設為 true ,然後將資料格加入至集合中 SelectedCellsWhen a cell is selected, the DataGridCell.Selected event is raised, the DataGridCell.IsSelected property is set to true, and the cell is added to the SelectedCells collection.

選取資料列時, DataGridRow.Selected 就會引發事件、將 DataGridRow.IsSelected 屬性設為 true ,然後將資料列加入至 SelectedItems 集合中。When a row is selected, the DataGridRow.Selected event is raised, the DataGridRow.IsSelected property is set to true, and the row is added to the SelectedItems collection.

當選取範圍變更時, SelectionChanged SelectedCellsChanged 如果新的或舊的選取範圍包含資料列,就會引發和事件。When the selection changes, the SelectionChanged and SelectedCellsChanged events are raised if the new or old selection contains a row. SelectionChanged如果新的或舊的選取範圍只包含資料格,就不會引發事件。The SelectionChanged event is not raised if the new or old selection contains only cells.