public virtual void InvalidateRows() { _rows.ForEach(r => r.Cells.Clear()); _rows.Clear(); _columns.ForEach(c => c.Cells.Clear()); _cells.Clear(); if (Items == null) { return; } foreach (var item in Items) { var row = new LiteRow { Item = item }; _rows.Add(row); foreach (var column in Columns) { var cell = column.GenerateCell(); _cells.Add(cell); row.Cells.Add(cell); column.Cells.Add(cell); } } }
private void CellMouseMove(object sender, MouseEventArgs e) { if (_mouseIsSelecting) { var cell = GetCellElement(sender as UIElement); if (cell == null) { return; } if (_selectAnchor == null) { _selectAnchor = GetCellElement(cell); } if (_selectAnchor.Equals(cell)) { SelectedCells = new[] { cell }; return; } var allRows = _rows.ToList(); var startRow = LiteRow.GetRow(_selectAnchor); var endRow = LiteRow.GetRow(cell); var startRowIndex = allRows.IndexOf(startRow); var endRowIndex = allRows.IndexOf(endRow); var rowFromIndex = Math.Min(startRowIndex, endRowIndex); var rowToIndex = Math.Max(startRowIndex, endRowIndex); var startCellIndex = startRow.Cells.IndexOf(_selectAnchor); var endCellIndex = endRow.Cells.IndexOf(cell); var cellFromIndex = Math.Min(startCellIndex, endCellIndex); var cellToIndex = Math.Max(startCellIndex, endCellIndex); var selection = new List <UIElement>(); for (var r = rowFromIndex; r <= rowToIndex; r++) { var selectRow = allRows[r]; for (var c = cellFromIndex; c <= cellToIndex; c++) { var selectCell = selectRow.Cells[c]; selection.Add(selectCell); } } selection.Remove(cell); selection.Insert(0, cell); SelectedCells = selection; } ; }
private static void SetRow(DependencyObject cell, LiteRow row) { cell.SetValue(RowProperty, row); }