/// <summary> /// Sort the current column /// </summary> /// <param name="e"></param> /// <param name="p_bAscending"></param> /// <param name="p_Comparer"></param> public void SortColumn(PositionEventArgs e, bool p_bAscending, System.Collections.IComparer p_Comparer) { //verifico che il sort sia abilitato e che ci sia almeno una riga da ordinare oltra a quella corrente if (IsSortEnable(e) && e.Position.Row < (e.Grid.RowsCount) && e.Grid.ColumnsCount > 0) { Range l_RangeToSort; Range l_RangeHeader; if (m_RangeToSort != null) { l_RangeToSort = m_RangeToSort.GetRange(e.Grid); } else { //the range to sort is all the grid range without the rows < of the current row l_RangeToSort = new Range(e.Position.Row + 1, 0, e.Grid.RowsCount - 1, e.Grid.ColumnsCount - 1); } if (m_HeaderRange != null) { l_RangeHeader = m_HeaderRange.GetRange(e.Grid); } else { //the range header is all the grid range with the rows <= of the current row l_RangeHeader = new Range(0, 0, e.Position.Row, e.Grid.ColumnsCount - 1); } ICellSortableHeader l_CellSortable = (ICellSortableHeader)e.Cell; if (e.Grid.RowsCount > (e.Position.Row + 1) && e.Grid.ColumnsCount > e.Grid.FixedColumns) { e.Grid.SortRangeRows(l_RangeToSort, e.Position.Column, p_bAscending, p_Comparer); if (p_bAscending) { l_CellSortable.SetSortMode(e.Position, GridSortMode.Ascending); } else { l_CellSortable.SetSortMode(e.Position, GridSortMode.Descending); } //Remove the image from others ColHeaderSort for (int r = l_RangeHeader.Start.Row; r <= l_RangeHeader.End.Row; r++) { for (int c = l_RangeHeader.Start.Column; c <= l_RangeHeader.End.Column; c++) { Cells.ICellVirtual l_tmp = e.Grid.GetCell(r, c); if (l_tmp != l_CellSortable && l_tmp != null && l_tmp is ICellSortableHeader) { ((ICellSortableHeader)l_tmp).SetSortMode(new Position(r, c), GridSortMode.None); } } } } } }
/// <summary> /// Indicates if for the specified cell the sort is enabled. /// </summary> /// <param name="e"></param> /// <returns></returns> public bool IsSortEnable(PositionEventArgs e) { if (e.Cell is ICellSortableHeader && m_bEnableSort) { ICellSortableHeader l_tmp = (ICellSortableHeader)e.Cell; SortStatus l_Status = l_tmp.GetSortStatus(e.Position); return(l_Status.EnableSort); } else { return(false); } }
/// <summary> /// Indicates whether sorting is enabled for the specified cell. /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.PositionEventArgs"/> instance containing the event data.</param> /// <returns> /// <c>true</c> if is sort enabled for the specified cell; otherwise, <c>false</c>. /// </returns> private bool IsSortEnable(PositionEventArgs e) { if (e.Cell is ICellSortableHeader && doEnableSort) { ICellSortableHeader sortableHeaderCell = (ICellSortableHeader)e.Cell; SortStatus sortStatus = sortableHeaderCell.GetSortStatus(e.Position); return(sortStatus.EnableSort); } else { return(false); } }
/// <summary> /// Handles the click event on the current cell /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.PositionEventArgs"/> instance containing the event data.</param> public override void OnClick(PositionEventArgs e) { base.OnClick(e); if (IsSortEnable(e) && (resize == null || (resize.IsHeightResizing == false && resize.IsWidthResizing == false))) { ICellSortableHeader sortableHeaderCell = (ICellSortableHeader)e.Cell; SortStatus sortStatus = sortableHeaderCell.GetSortStatus(e.Position); if (sortStatus.EnableSort) { SortColumn(e, sortStatus.Mode != GridSortMode.Ascending, sortStatus.Comparer); } } }
/// <summary> /// Sort the current column /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.PositionEventArgs"/> instance containing the event data.</param> /// <param name="doAscending">if set to <c>true</c> sort in ascending order.</param> /// <param name="comparer">The comparer.</param> private void SortColumn(PositionEventArgs e, bool doAscending, IComparer comparer) { if (IsSortEnable(e) && e.Position.Row < e.Grid.RowsCount && e.Grid.ColumnsCount > 0) { Range l_RangeToSort; Range l_RangeHeader; if (rangeToSort != null) { l_RangeToSort = rangeToSort.GetRange(e.Grid); } else { // the range to sort is all the grid range without the rows < of the current row l_RangeToSort = new Range(e.Position.Row + 1, 0, e.Grid.RowsCount - 1, e.Grid.ColumnsCount - 1); } if (headerRange != null) { l_RangeHeader = headerRange.GetRange(e.Grid); } else { // the range header is all the grid range with the rows <= of the current row l_RangeHeader = new Range(0, 0, e.Position.Row, e.Grid.ColumnsCount - 1); } if (e.Grid.RowsCount > e.Grid.FixedRows && e.Grid.ColumnsCount > e.Grid.FixedColumns) { e.Grid.SortRangeRows(l_RangeToSort, e.Position.Column, doAscending, comparer); ICellSortableHeader l_CellSortable = (ICellSortableHeader)e.Cell; l_CellSortable.SetSortMode(e.Position, doAscending == true ? GridSortMode.Ascending : GridSortMode.Descending); // Remove the image from others for (int r = l_RangeHeader.Start.Row; r <= l_RangeHeader.End.Row; r++) { for (int c = l_RangeHeader.Start.Column; c <= l_RangeHeader.End.Column; c++) { Cells.ICellVirtual l_tmp = e.Grid.GetCell(r, c); if (l_tmp != null && l_tmp is ICellSortableHeader && c != e.Position.Column) { ((ICellSortableHeader)l_tmp).SetSortMode(new Position(r, c), GridSortMode.None); } } } } } }
/// <summary> /// Draw the image and the displaystring of the specified cell. /// </summary> /// <param name="p_Cell"></param> /// <param name="p_CellPosition"></param> /// <param name="e">Paint arguments</param> /// <param name="p_ClientRectangle">Rectangle position where draw the current cell, relative to the current view,</param> /// <param name="p_Status"></param> protected override void DrawCell_ImageAndText(SourceGrid2.Cells.ICellVirtual p_Cell, Position p_CellPosition, PaintEventArgs e, Rectangle p_ClientRectangle, DrawCellStatus p_Status) { base.DrawCell_ImageAndText(p_Cell, p_CellPosition, e, p_ClientRectangle, p_Status); if (p_Cell is ICellSortableHeader) { ICellSortableHeader l_Header = (ICellSortableHeader)p_Cell; SortStatus l_Status = l_Header.GetSortStatus(p_CellPosition); if (l_Status.Mode == GridSortMode.Ascending) { Utility.PaintImageAndText(e.Graphics, p_ClientRectangle, CommonImages.SortUp, ContentAlignment.MiddleRight, false, null, null, false, Border, Color.Black, null); } else if (l_Status.Mode == GridSortMode.Descending) { Utility.PaintImageAndText(e.Graphics, p_ClientRectangle, CommonImages.SortDown, ContentAlignment.MiddleRight, false, null, null, false, Border, Color.Black, null); } } }
public override void OnClick(PositionEventArgs e) { base.OnClick(e); //eseguo il sort solo se non sono attualmente in resize if (IsSortEnable(e) && (m_Resize == null || (m_Resize.IsHeightResizing == false && m_Resize.IsWidthResizing == false))) { ICellSortableHeader l_tmp = (ICellSortableHeader)e.Cell; SortStatus l_Status = l_tmp.GetSortStatus(e.Position); if (l_Status.EnableSort) { if (l_Status.Mode == GridSortMode.Ascending) { SortColumn(e, false, l_Status.Comparer); } else { SortColumn(e, true, l_Status.Comparer); } } } }