示例#1
0
        /// <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>
        /// 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);
                            }
                        }
                    }
                }
            }
        }