DataGrid.SelectedCells 属性

定义

获取当前选定单元格的列表。Gets the list of cells that are currently selected.

public:
 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)

属性值

IList<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 ,并将该单元格添加到 SelectedCells 集合中。When 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.

适用于