/// <summary> /// Instantiates a new instance of this class. /// </summary> public DataGrid() { _columns = new DataGridColumnCollection(this); _columns.CollectionChanged += new NotifyCollectionChangedEventHandler(OnColumnsChanged); _rowValidationRules = new ObservableCollection<ValidationRule>(); _rowValidationRules.CollectionChanged += new NotifyCollectionChangedEventHandler(OnRowValidationRulesChanged); _selectedCells = new SelectedCellsCollection(this); ((INotifyCollectionChanged)Items).CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemsCollectionChanged); ((INotifyCollectionChanged)Items.SortDescriptions).CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemsSortDescriptionsChanged); Items.GroupDescriptions.CollectionChanged += new NotifyCollectionChangedEventHandler(OnItemsGroupDescriptionsChanged); // Compute column widths but wait until first load InternalColumns.InvalidateColumnWidthsComputation(); CellsPanelHorizontalOffsetComputationPending = false; }
/// <summary> /// Selects cells of the <see cref="XamGrid"/>. /// </summary> /// <param name="grid">The <see cref="XamGrid"/>.</param> /// <param name="cellsToSelect">The cells that will be selected.</param> private static void SelectCells(this XamGrid grid, IEnumerable<Cell> cellsToSelect) { if (cellsToSelect.Any()) { grid.SelectionSettings.SelectedCells.Clear(); } using (var selectedCollection = new SelectedCellsCollection()) { foreach (var cell in cellsToSelect) { selectedCollection.Add(cell); } grid.SelectionSettings.SelectedCells.AddRange(selectedCollection); } }