/// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public ListSortDescriptionCollection(ListSortDescription[] sorts) {
     if (sorts != null) {
         for (int i = 0; i < sorts.Length; i ++) {
             this.sorts.Add(sorts[i]);
         }
     }
 }
Exemplo n.º 2
0
		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);
		}
Exemplo n.º 3
0
		/// <summary>
		/// Sorts the view of the underlying list based on the given <see cref="T:System.ComponentModel.ListSortDescriptionCollection"></see>.
		/// </summary>
		/// <param name="sorts">The <see cref="T:System.ComponentModel.ListSortDescriptionCollection"></see> containing the sorts to apply to the view.</param>
		public void ApplySort(ListSortDescriptionCollection sorts)
		{
			Lock();

			try
			{
				ListSortDescriptionCollection proposed;

				if (sorts == null)
					proposed = new ListSortDescriptionCollection();
				else
				{
					foreach (ListSortDescription desc in sorts)
						ValidateProperty(desc.PropertyDescriptor);

					ListSortDescription[] props = new ListSortDescription[sorts.Count];
					sorts.CopyTo(props, 0);
					proposed = new ListSortDescriptionCollection(props);
				}

				this.SortProperties = proposed;
			}
			finally
			{
				Unlock();
			}

			RaiseEvents();
		}
Exemplo n.º 4
0
		/// <summary>
		/// Sorts the view based on a <see cref="T:System.ComponentModel.PropertyDescriptor"></see> and a <see cref="T:System.ComponentModel.ListSortDirection"></see>.
		/// </summary>
		/// <param name="property">The <see cref="T:System.ComponentModel.PropertyDescriptor"></see> to sort by.</param>
		/// <param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection"></see> values.</param>
		public void ApplySort(PropertyDescriptor property, ListSortDirection direction)
		{
			Lock();

			try
			{
				ListSortDescriptionCollection proposed;

				if (property == null)
					proposed = new ListSortDescriptionCollection();
				else
				{
					ValidateProperty(property);

					ListSortDescription[] props = new ListSortDescription[] { new ListSortDescription(property, direction) };
					proposed = new ListSortDescriptionCollection(props);
				}

				this.SortProperties = proposed;
			}
			finally
			{
				Unlock();
			}

			RaiseEvents();
		}
Exemplo n.º 5
0
        // << Some of this code is taken from System.Data.DataTable::ParseSortString method >>
        private ListSortDescriptionCollection ParseSortString(string sortString) {
            if (String.IsNullOrEmpty(sortString)) {
                return new ListSortDescriptionCollection();
            }

            ArrayList sorts = new ArrayList();
            PropertyDescriptorCollection props = this.currencyManager.GetItemProperties();

            string[] split = sortString.Split(new char[] {','});
            for (int i = 0; i < split.Length; i++) {
                string current = split[i].Trim();

                // Handle ASC and DESC
                int length = current.Length;
                bool ascending = true;
                if (length >= 5 && String.Compare(current, length - 4, " ASC", 0, 4, true, CultureInfo.InvariantCulture) == 0) {
                    current = current.Substring(0, length - 4).Trim();
                }
                else if (length >= 6 && String.Compare(current, length - 5, " DESC", 0, 5, true, CultureInfo.InvariantCulture) == 0) {
                    ascending = false;
                    current = current.Substring(0, length - 5).Trim();
                }

                // Handle brackets
                if (current.StartsWith("[")) {
                    if (current.EndsWith("]")) {
                        current = current.Substring(1, current.Length - 2);
                    }
                    else {
                        throw new ArgumentException(SR.GetString(SR.BindingSourceBadSortString));
                    }
                }

                // Find the property
                PropertyDescriptor prop = props.Find(current, true);
                if (prop == null) {
                    throw new ArgumentException(SR.GetString(SR.BindingSourceSortStringPropertyNotInIBindingList));
                }

                // Add the sort description
                sorts.Add(new ListSortDescription(prop, ascending ? ListSortDirection.Ascending : ListSortDirection.Descending));
            }

            ListSortDescription[] result = new ListSortDescription[sorts.Count];
            sorts.CopyTo(result);
            return new ListSortDescriptionCollection(result);
        }
 public ListSortDescriptionCollection(ListSortDescription[] sorts)
 {
 }
Exemplo n.º 7
0
		// NOTE: Probably the parsing can be improved
		void ProcessSortString (string sort)
		{
			// Only keep simple whitespaces in the middle
			sort = Regex.Replace (sort, "( )+", " ");

			string [] properties = sort.Split (',');
			PropertyDescriptorCollection prop_descs = GetItemProperties (null);
			if (properties.Length == 1) {
				ListSortDescription sort_desc = GetListSortDescription (prop_descs, properties [0]);
				ApplySort (sort_desc.PropertyDescriptor, sort_desc.SortDirection);
			} else {
				if (!SupportsAdvancedSorting)
					throw new ArgumentException ("value");

				ListSortDescription [] sort_descs = new ListSortDescription [properties.Length];
				for (int i = 0; i < properties.Length; i++)
					sort_descs [i] = GetListSortDescription (prop_descs, properties [i]);

				ApplySort (new ListSortDescriptionCollection (sort_descs));
			}

		}
Exemplo n.º 8
0
		//-------------------------------------------------------------------------------------
		void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction)
		{
			ListSortDescription lsd = new ListSortDescription(property, direction);
			if(_sorts == null)
			 _sorts = new List<ListSortDescription>();
			int pos = _sorts.FindIndex(delegate(ListSortDescription l)
			{
				return l.PropertyDescriptor.Name == lsd.PropertyDescriptor.Name;
			});
			if(pos == -1)
			{
				_sorts.Clear();
				_sorts.Add(lsd);
			}
			else
				_sorts[pos] = lsd;
			ApplySort(DefaultSorter);
		}
 private ListSortDescriptionCollection ParseSortString(string sortString)
 {
     if (string.IsNullOrEmpty(sortString))
     {
         return new ListSortDescriptionCollection();
     }
     ArrayList list = new ArrayList();
     PropertyDescriptorCollection itemProperties = this.currencyManager.GetItemProperties();
     string[] strArray = sortString.Split(new char[] { ',' });
     for (int i = 0; i < strArray.Length; i++)
     {
         string strA = strArray[i].Trim();
         int length = strA.Length;
         bool flag = true;
         if ((length >= 5) && (string.Compare(strA, length - 4, " ASC", 0, 4, true, CultureInfo.InvariantCulture) == 0))
         {
             strA = strA.Substring(0, length - 4).Trim();
         }
         else if ((length >= 6) && (string.Compare(strA, length - 5, " DESC", 0, 5, true, CultureInfo.InvariantCulture) == 0))
         {
             flag = false;
             strA = strA.Substring(0, length - 5).Trim();
         }
         if (strA.StartsWith("["))
         {
             if (!strA.EndsWith("]"))
             {
                 throw new ArgumentException(System.Windows.Forms.SR.GetString("BindingSourceBadSortString"));
             }
             strA = strA.Substring(1, strA.Length - 2);
         }
         PropertyDescriptor property = itemProperties.Find(strA, true);
         if (property == null)
         {
             throw new ArgumentException(System.Windows.Forms.SR.GetString("BindingSourceSortStringPropertyNotInIBindingList"));
         }
         list.Add(new ListSortDescription(property, flag ? ListSortDirection.Ascending : ListSortDirection.Descending));
     }
     ListSortDescription[] array = new ListSortDescription[list.Count];
     list.CopyTo(array);
     return new ListSortDescriptionCollection(array);
 }
Exemplo n.º 10
0
		private IComparer GetSortComparer(ListSortDescriptionCollection sortDescriptions)
		{
			bool needSubstitution = false;

			if (_sortSubstitutions.Count > 0)
			{
				foreach (ListSortDescription sortDescription in sortDescriptions)
				{
					if (_sortSubstitutions.ContainsKey(sortDescription.PropertyDescriptor.Name))
					{
						needSubstitution = true;
						break;
					}
				}

				if (needSubstitution)
				{
					ListSortDescription[] sorts = new ListSortDescription[sortDescriptions.Count];
					sortDescriptions.CopyTo(sorts, 0);

					for (int i = 0; i < sorts.Length; i++)
						if (_sortSubstitutions.ContainsKey(sorts[i].PropertyDescriptor.Name))
							sorts[i] = new ListSortDescription(((SortSubstitutionPair)_sortSubstitutions[sorts[i].PropertyDescriptor.Name]).Substitute, 
								                               sorts[i].SortDirection);

					sortDescriptions = new ListSortDescriptionCollection(sorts);
				}
			}

			return new SortListPropertyComparer(sortDescriptions);
		}
Exemplo n.º 11
0
		//-------------------------------------------------------------------------------------
		private void AddSortColumn(DataGridViewColumn col, ListSortDirection direction = ListSortDirection.Ascending)
		{
			if(this.DataSource == null)// || props.ContainsKey(col.DataPropertyName) == false)
				return;
			try
			{
				if(AllowMultipleSort == false)
				{
					if((this.DataSource as IBindingList) == null)
						throw new Exception(String.Format("»сточник данных [{0}] не поддерживает интерфейс IBindingList!",
																																								DataSource.GetType().FullName));
					IBindingList ibl = (IBindingList)this.DataSource;
					if(ibl.SupportsSorting == false)
						return;
					PropertyDescriptor pd = null;
					if(props.ContainsKey(col.DataPropertyName))
						pd = props[col.DataPropertyName];
					else
						pd = new UnboundColumnPropertyDescriptor(col);
					ListSortDirection lsd = direction;
					if(ibl.SortProperty != null && Object.Equals(ibl.SortProperty, pd))
						if(ibl.SortDirection == ListSortDirection.Ascending)
							lsd = ListSortDirection.Descending;
						else
							lsd = ListSortDirection.Ascending;
					ibl.ApplySort(pd, lsd);
					foreach(DataGridViewColumn c in Columns)
						c.HeaderCell.SortGlyphDirection = SortOrder.None;
					if(lsd == ListSortDirection.Ascending)
						col.HeaderCell.SortGlyphDirection = SortOrder.Ascending;
					else
						col.HeaderCell.SortGlyphDirection = SortOrder.Descending;
					SortedColumn = col;
					SortOrder = lsd == ListSortDirection.Ascending ? SortOrder.Ascending : SortOrder.Descending;
				}
				else
				{
					if((this.DataSource as IBindingListView) == null)
						throw new Exception(String.Format("»сточник данных [{0}] не поддерживает интерфейс IBindingListView!",
																																								DataSource.GetType().FullName));
					if((this.DataSource as ITypedList) == null)
						throw new Exception(String.Format("»сточник данных [{0}] не поддерживает интерфейс ITypedList !",
																																								DataSource.GetType().FullName));
					if(((IBindingListView)DataSource).SupportsAdvancedSorting == false)
						throw new Exception(String.Format("»сточник данных [{0}] не поддерживает сортировку по нескольким столбцам!",
																																								DataSource.GetType().FullName));

					PDictionary<string, ListSortDescription> sl = new PDictionary<string, ListSortDescription>();

					if(((IBindingListView)DataSource).SortDescriptions != null)
						foreach(ListSortDescription lsd in ((IBindingListView)DataSource).SortDescriptions)
							sl.Add(lsd.PropertyDescriptor.Name, lsd);

					List<string> toDel = new List<string>();
					if(ModifierKeys != Keys.Control)
						foreach(string s in sl.Keys)
							if(s != (String.IsNullOrEmpty(col.DataPropertyName) ? col.Name : col.DataPropertyName))
								toDel.Add(s);
					foreach(string s in toDel)
						sl.Remove(s);

					PropertyDescriptor pd = null;
					if(props.ContainsKey(col.DataPropertyName))
						pd = props[col.DataPropertyName];
					else
						pd = new UnboundColumnPropertyDescriptor(col);
					if(sl.ContainsKey(pd.Name))
					{
						if(sl[pd.Name].SortDirection == ListSortDirection.Ascending)
							sl[pd.Name].SortDirection = ListSortDirection.Descending;
						else
							sl[pd.Name].SortDirection = ListSortDirection.Ascending;
					}
					else
						sl.Add(pd.Name, new ListSortDescription(pd, direction));
					SortedColumn = col;
					SortOrder = sl[pd.Name].SortDirection == ListSortDirection.Ascending ? SortOrder.Ascending : SortOrder.Descending;
					ListSortDescription[] sd = new ListSortDescription[sl.Count];
					int c = 0;
					foreach(var i in sl.Values)
						sd[c++] = i;
					((IBindingListView)DataSource).ApplySort(new ListSortDescriptionCollection(sd));

					DrawMultiSort();

				}
				this.Refresh();
			}
			catch(Exception Err)
			{
				ErrorBox.Show(Err);
			}
		}
Exemplo n.º 12
0
		//-------------------------------------------------------------------------------------
		void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction)
		{
			comparer = null;
			ListSortDescription lsd = new ListSortDescription(property, direction);
			int pos = sort.FindIndex(delegate(ListSortDescription l)
																													{
																														return l.PropertyDescriptor.Name == lsd.PropertyDescriptor.Name;
																													});
			if(pos == -1)
			{
				sort.Clear();
				sort.Add(lsd);
			}
			else
				sort[pos] = lsd;
			
			Sort();
		}
        // convert from Avalon SortDescriptions to the corresponding .NET collection
        private ListSortDescriptionCollection ConvertSortDescriptionCollection(SortDescriptionCollection sorts)
        {
            PropertyDescriptorCollection pdc;
            ITypedList itl;
            Type itemType;

            if ((itl = InternalList as ITypedList) != null)
            {
                pdc = itl.GetItemProperties(null);
            }
            else if ((itemType = GetItemType(true)) != null)
            {
                pdc = TypeDescriptor.GetProperties(itemType);
            }
            else
            {
                pdc = null;
            }

            if ((pdc == null) || (pdc.Count == 0))
                throw new ArgumentException(SR.Get(SRID.CannotDetermineSortByPropertiesForCollection));

            ListSortDescription[] sortDescriptions = new ListSortDescription[sorts.Count];
            for (int i = 0; i < sorts.Count; i++)
            {
                PropertyDescriptor dd = pdc.Find(sorts[i].PropertyName, true);
                if (dd == null)
                {
                    string typeName = itl.GetListName(null);
                    throw new ArgumentException(SR.Get(SRID.PropertyToSortByNotFoundOnType, typeName, sorts[i].PropertyName));
                }
                ListSortDescription sd = new ListSortDescription(dd, sorts[i].Direction);
                sortDescriptions[i] = sd;
            }

            return new ListSortDescriptionCollection(sortDescriptions);
        }
		public ListSortDescriptionCollection (ListSortDescription[] sorts) {
			list = new ArrayList();
			foreach (ListSortDescription item in sorts)
				list.Add (item);
		}