Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Makes the specified field the first, or primary, field on which to sort.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public bool SetPrimarySortField(PaField field, bool changeDirection, bool ascending)
        {
            if (field == null)
            {
                return(ascending);
            }

            var sortInfo = SortFields.SingleOrDefault(si => si.Field.Name == field.Name);
            int index    = (sortInfo == null ? -1 : SortFields.IndexOf(sortInfo));

            // If the sort information list already contains an item for the specified field,
            // we need to remove it before reinserting it at the beginning of the list.
            if (index > -1)
            {
                if (changeDirection)
                {
                    ascending = SortFields[index].Ascending;
                }
                SortFields.RemoveAt(index);
            }

            if (changeDirection)
            {
                ascending = !ascending;
            }

            // Now insert an item at the beginning of the list since the specified field
            // has now become the first (i.e. primary) field on which to sort.
            SortFields.Insert(0, new SortField(field, ascending));

            return(ascending);
        }