protected override void OnSortingRangeRows(SortRangeRowsEventArgs e) { base.OnSortingRangeRows(e); if (DataSource == null || DataSource.AllowSort == false) { return; } System.ComponentModel.PropertyDescriptor propertyCol = Columns[e.KeyColumn].PropertyColumn; if (propertyCol != null) { ListSortDirection direction; if (e.Ascending) { direction = ListSortDirection.Ascending; } else { direction = ListSortDirection.Descending; } ListSortDescription[] sortsArray = new ListSortDescription[1]; sortsArray[0] = new ListSortDescription(propertyCol, direction); DataSource.ApplySort(new ListSortDescriptionCollection(sortsArray)); } else { DataSource.ApplySort(null); } }
protected override void OnSortingRangeRows(SortRangeRowsEventArgs e) { base.OnSortingRangeRows(e); string l_SortMode; if (e.Ascending) { l_SortMode = " ASC"; } else { l_SortMode = " DESC"; } System.Data.DataColumn dataCol = Columns[e.KeyColumn].DataColumn; if (dataCol != null) { DataSource.Sort = dataCol.ColumnName + l_SortMode; } else { DataSource.Sort = null; } }
/// <summary> /// when sorting /// </summary> /// <param name="e"></param> protected override void OnSortingRangeRows(SourceGrid.SortRangeRowsEventArgs e) { base.OnSortingRangeRows(e); if (!FPerformFullLoadOnDataGridSort) { FPerformFullLoadOnDataGridSort = true; LoadAllDataPages(); } }
protected override void OnSortingRangeRows(SortRangeRowsEventArgs e) { base.OnSortingRangeRows (e); if (DataSource == null || DataSource.AllowSort == false) return; System.ComponentModel.PropertyDescriptor propertyCol = Columns[e.KeyColumn].PropertyColumn; if (propertyCol != null) { ListSortDirection direction; if (e.Ascending) direction = ListSortDirection.Ascending; else direction = ListSortDirection.Descending; ListSortDescription[] sortsArray = new ListSortDescription[1]; sortsArray[0] = new ListSortDescription(propertyCol, direction); DataSource.ApplySort(new ListSortDescriptionCollection(sortsArray)); } else DataSource.ApplySort(null); }
/// <summary> /// Fired when calling SortRangeRows method. If the range contains all the columns this method move directly the row object otherwise move each cell. /// </summary> /// <param name="e"></param> protected override void OnSortingRangeRows(SortRangeRowsEventArgs e) { base.OnSortingRangeRows(e); if (CustomSort) return; if (e.KeyColumn > e.Range.End.Column && e.KeyColumn < e.Range.Start.Column) throw new ArgumentException("Invalid range", "e.KeyColumn"); System.Collections.IComparer cellComparer = e.CellComparer; if (cellComparer == null) cellComparer = new ValueCellComparer(); //Sort all the columns (in this case I move directly the row object) if (e.Range.ColumnsCount == ColumnsCount) { RowInfo[] rowInfoToSort = new RowInfo[e.Range.End.Row-e.Range.Start.Row+1]; Cells.ICell[] cellKeys = new Cells.ICell[e.Range.End.Row-e.Range.Start.Row+1]; int zeroIndex = 0; for (int r = e.Range.Start.Row; r <= e.Range.End.Row;r++) { cellKeys[zeroIndex] = this[r, e.KeyColumn]; rowInfoToSort[zeroIndex] = Rows[r]; zeroIndex++; } Array.Sort(cellKeys, rowInfoToSort, 0, cellKeys.Length, cellComparer); //Apply sort if (e.Ascending) { for (zeroIndex = 0; zeroIndex < rowInfoToSort.Length; zeroIndex++) { Rows.Swap( rowInfoToSort[zeroIndex].Index, e.Range.Start.Row + zeroIndex); } } else //desc { for (zeroIndex = rowInfoToSort.Length-1; zeroIndex >= 0; zeroIndex--) { Rows.Swap( rowInfoToSort[zeroIndex].Index, e.Range.End.Row - zeroIndex); } } } else //sort only the specified range { Cells.ICell[][] l_RangeSort = new Cells.ICell[e.Range.End.Row-e.Range.Start.Row+1][]; Cells.ICell[] l_CellsKeys = new Cells.ICell[e.Range.End.Row-e.Range.Start.Row+1]; int zeroRowIndex = 0; for (int r = e.Range.Start.Row; r <= e.Range.End.Row;r++) { l_CellsKeys[zeroRowIndex] = this[r, e.KeyColumn]; int zeroColIndex = 0; l_RangeSort[zeroRowIndex] = new Cells.ICell[e.Range.End.Column-e.Range.Start.Column+1]; for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++) { l_RangeSort[zeroRowIndex][zeroColIndex] = this[r,c]; zeroColIndex++; } zeroRowIndex++; } Array.Sort(l_CellsKeys, l_RangeSort, 0, l_CellsKeys.Length, cellComparer); //Apply sort zeroRowIndex = 0; if (e.Ascending) { for (int r = e.Range.Start.Row; r <= e.Range.End.Row;r++) { int zeroColIndex = 0; for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++) { RemoveCell(r,c);//rimuovo qualunque cella nella posizione corrente Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex]; if (tmp!=null && tmp.Grid!=null && tmp.Range.Start.Row>=0 && tmp.Range.Start.Column>=0) //verifico che la cella sia valida RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column);//la rimuovo dalla posizione precedente this[r,c] = tmp; zeroColIndex++; } zeroRowIndex++; } } else //desc { for (int r = e.Range.End.Row; r >= e.Range.Start.Row;r--) { int zeroColIndex = 0; for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++) { RemoveCell(r,c);//rimuovo qualunque cella nella posizione corrente Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex]; if (tmp!=null && tmp.Grid!=null && tmp.Range.Start.Row >= 0 && tmp.Range.Start.Column >= 0) //verifico che la cella sia valida RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column);//la rimuovo dalla posizione precedente this[r,c] = tmp; zeroColIndex++; } zeroRowIndex++; } } } }
/// <summary> /// Fired after calling SortRangeRows method /// </summary> /// <param name="e"></param> protected virtual void OnSortedRangeRows(SortRangeRowsEventArgs e) { }
/// <summary> /// Sort a range of the grid. /// </summary> /// <param name="p_Range"></param> /// <param name="keyColumn">Index of the column relative to the grid to use as sort keys, must be between start and end col</param> /// <param name="p_bAscending">Ascending true, Descending false</param> /// <param name="p_CellComparer">CellComparer, if null the default ValueCellComparer comparer will be used</param> public void SortRangeRows(Range p_Range, int keyColumn, bool p_bAscending, IComparer p_CellComparer) { SortRangeRowsEventArgs eventArgs = new SortRangeRowsEventArgs(p_Range, keyColumn, p_bAscending, p_CellComparer); if (SortingRangeRows!=null) SortingRangeRows(this, eventArgs); OnSortingRangeRows(eventArgs); if (SortedRangeRows!=null) SortedRangeRows(this, eventArgs); OnSortedRangeRows(eventArgs); }
/// <summary> /// Fired when calling SortRangeRows method. If the range contains all the columns this method move directly the row object otherwise move each cell. /// </summary> /// <param name="e"></param> protected override void OnSortingRangeRows(SortRangeRowsEventArgs e) { base.OnSortingRangeRows(e); if (CustomSort) { return; } if (e.KeyColumn > e.Range.End.Column && e.KeyColumn < e.Range.Start.Column) { throw new ArgumentException("Invalid range", "e.KeyColumn"); } System.Collections.IComparer cellComparer = e.CellComparer; if (cellComparer == null) { cellComparer = new ValueCellComparer(); } //Sort all the columns (in this case I move directly the row object) if (e.Range.ColumnsCount == ColumnsCount) { RowInfo[] rowInfoToSort = new RowInfo[e.Range.End.Row - e.Range.Start.Row + 1]; Cells.ICell[] cellKeys = new Cells.ICell[e.Range.End.Row - e.Range.Start.Row + 1]; int zeroIndex = 0; for (int r = e.Range.Start.Row; r <= e.Range.End.Row; r++) { cellKeys[zeroIndex] = this[r, e.KeyColumn]; rowInfoToSort[zeroIndex] = Rows[r]; zeroIndex++; } Array.Sort(cellKeys, rowInfoToSort, 0, cellKeys.Length, cellComparer); //Apply sort if (e.Ascending) { for (zeroIndex = 0; zeroIndex < rowInfoToSort.Length; zeroIndex++) { Rows.Swap(rowInfoToSort[zeroIndex].Index, e.Range.Start.Row + zeroIndex); } } else //desc { for (zeroIndex = rowInfoToSort.Length - 1; zeroIndex >= 0; zeroIndex--) { Rows.Swap(rowInfoToSort[zeroIndex].Index, e.Range.End.Row - zeroIndex); } } } else //sort only the specified range { Cells.ICell[][] l_RangeSort = new Cells.ICell[e.Range.End.Row - e.Range.Start.Row + 1][]; Cells.ICell[] l_CellsKeys = new Cells.ICell[e.Range.End.Row - e.Range.Start.Row + 1]; int zeroRowIndex = 0; for (int r = e.Range.Start.Row; r <= e.Range.End.Row; r++) { l_CellsKeys[zeroRowIndex] = this[r, e.KeyColumn]; int zeroColIndex = 0; l_RangeSort[zeroRowIndex] = new Cells.ICell[e.Range.End.Column - e.Range.Start.Column + 1]; for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++) { l_RangeSort[zeroRowIndex][zeroColIndex] = this[r, c]; zeroColIndex++; } zeroRowIndex++; } Array.Sort(l_CellsKeys, l_RangeSort, 0, l_CellsKeys.Length, cellComparer); //Apply sort zeroRowIndex = 0; if (e.Ascending) { for (int r = e.Range.Start.Row; r <= e.Range.End.Row; r++) { int zeroColIndex = 0; for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++) { RemoveCell(r, c); //rimuovo qualunque cella nella posizione corrente Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex]; if (tmp != null && tmp.Grid != null && tmp.Range.Start.Row >= 0 && tmp.Range.Start.Column >= 0) //verifico che la cella sia valida { RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column); //la rimuovo dalla posizione precedente } this[r, c] = tmp; zeroColIndex++; } zeroRowIndex++; } } else //desc { for (int r = e.Range.End.Row; r >= e.Range.Start.Row; r--) { int zeroColIndex = 0; for (int c = e.Range.Start.Column; c <= e.Range.End.Column; c++) { RemoveCell(r, c); //rimuovo qualunque cella nella posizione corrente Cells.ICell tmp = l_RangeSort[zeroRowIndex][zeroColIndex]; if (tmp != null && tmp.Grid != null && tmp.Range.Start.Row >= 0 && tmp.Range.Start.Column >= 0) //verifico che la cella sia valida { RemoveCell(tmp.Range.Start.Row, tmp.Range.Start.Column); //la rimuovo dalla posizione precedente } this[r, c] = tmp; zeroColIndex++; } zeroRowIndex++; } } } }