语言

DataGrid.SelectedCells 属性

定义

获取当前所选单元格的列表。

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)

属性值

当前所选单元格的列表。

注解

有三种选择模式。DataGrid 选择模式是使用属性设置的 SelectionUnit 。 根据具体情况SelectionUnitSelectedCells,或SelectedItems将包含下表中定义的选定项的集合。

DataGridSelectionUnit 值 SelectedCells 值 SelectedItems 值
Cell 所选单元格的集合 空
FullRow 选定行中的单元格集合 所选行的集合
CellOrRowHeader 所选单元格的集合,包括所选行中的所有单元格 选定行的集合,如果未选择完整行,则为空

选择单元格时, DataGridCell.Selected 将引发该事件,将 DataGridCell.IsSelected 属性设置为 true该属性,并将该单元格添加到 SelectedCells 集合中。

选择行后, DataGridRow.Selected 将引发该事件,将 DataGridRow.IsSelected 属性设置为 true该行,并将该行添加到 SelectedItems 集合中。

选择发生更改时,如果新的或旧的选定内容包含行, SelectionChanged 将引发事件 SelectedCellsChanged 。 SelectionChanged如果新选项或旧选定内容仅包含单元格,则不会引发该事件。

适用于