IRawElementProviderSimple[] ISelectionProvider.GetSelection() { EnsureEnabled(); if (this.OwningDataGrid != null && this.OwningDataGridPeer != null && this.OwningDataGrid.SelectedItems != null && _group.GroupItems.Count /*ItemCount*/ > 0) { DataGridRowGroupInfo groupInfo = this.OwningDataGrid.RowGroupInfoFromCollectionViewGroup(_group); if (groupInfo != null) { // See which of the selected items are contained within this group List <IRawElementProviderSimple> selectedProviders = new List <IRawElementProviderSimple>(); int startRowIndex = groupInfo.Slot - this.OwningDataGrid.RowGroupHeadersTable.GetIndexCount(0, groupInfo.Slot) + 1; foreach (object item in this.OwningDataGrid.GetSelectionInclusive(startRowIndex, startRowIndex + _group.GroupItems.Count /*ItemCount*/ - 1)) { DataGridItemAutomationPeer peer = this.OwningDataGridPeer.GetOrCreateItemPeer(item); if (peer != null) { selectedProviders.Add(ProviderFromPeer(peer)); } } return(selectedProviders.ToArray()); } } return(null); }
void IScrollItemProvider.ScrollIntoView() { EnsureEnabled(); if (this.OwningDataGrid != null) { DataGridRowGroupInfo groupInfo = this.OwningDataGrid.RowGroupInfoFromCollectionViewGroup(_group); if (groupInfo != null) { this.OwningDataGrid.ScrollIntoView(groupInfo.CollectionViewGroup, null); } } }
IRawElementProviderSimple IGridProvider.GetItem(int row, int column) { EnsureEnabled(); if (this.OwningDataGrid != null && this.OwningDataGrid.DataConnection != null && row >= 0 && row < _group.GroupItems.Count /*ItemCount*/ && column >= 0 && column < this.OwningDataGrid.Columns.Count) { DataGridRowGroupInfo groupInfo = this.OwningDataGrid.RowGroupInfoFromCollectionViewGroup(_group); if (groupInfo != null) { // Adjust the row index to be relative to the DataGrid instead of the group row = groupInfo.Slot - this.OwningDataGrid.RowGroupHeadersTable.GetIndexCount(0, groupInfo.Slot) + row + 1; Debug.Assert(row >= 0, "Expected positive row."); Debug.Assert(row < this.OwningDataGrid.DataConnection.Count, "Expected row smaller than this.OwningDataGrid.DataConnection.Count."); int slot = this.OwningDataGrid.SlotFromRowIndex(row); if (!this.OwningDataGrid.IsSlotVisible(slot)) { object item = this.OwningDataGrid.DataConnection.GetDataItem(row); this.OwningDataGrid.ScrollIntoView(item, this.OwningDataGrid.Columns[column]); } Debug.Assert(this.OwningDataGrid.IsSlotVisible(slot), "Expected OwningDataGrid.IsSlotVisible(slot) is true."); DataGridRow dgr = this.OwningDataGrid.DisplayData.GetDisplayedElement(slot) as DataGridRow; // the first cell is always the indentation filler cell if grouping is enabled, so skip it Debug.Assert(column + 1 < dgr.Cells.Count, "Expected column + 1 smaller than dgr.Cells.Count."); DataGridCell cell = dgr.Cells[column + 1]; AutomationPeer peer = CreatePeerForElement(cell); if (peer != null) { return(ProviderFromPeer(peer)); } } } return(null); }