Click here to Skip to main content
12,349,582 members (29,068 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads

Stats

143.8K views
3.6K downloads
75 bookmarked
Posted

Databinding the SqlTypes

, 1 May 2003
Databinding the SqlTypes using the PropertyDescriptor class and the ITypedList Interface
using System;
using System.Collections;

namespace ITypedListExample
{
	/// <summary>
	/// Summary description for ObjectComparer.
	/// </summary>
	public class ObjectPropertyComparer : IComparer
	{
		private string PropertyName;

		/// <summary>
		/// Provides Comparison opreations.
		/// </summary>
		/// <param name="propertyName">The property to compare</param>
		public ObjectPropertyComparer( string propertyName)
		{
			PropertyName = propertyName;
		}

		/// <summary>
		/// Compares 2 objects by their properties, given on the constructor
		/// </summary>
		/// <param name="x">First value to compare</param>
		/// <param name="y">Second value to compare</param>
		/// <returns></returns>
		public int Compare(object x, object y)
		{
			object a = x.GetType().GetProperty(PropertyName).GetValue(x, null);
			object b = y.GetType().GetProperty(PropertyName).GetValue(y, null);

			if ( a != null && b == null )
				return 1;

			if ( a == null && b != null )
				return -1;

			if ( a == null && b == null )
				return 0;

			return ((IComparable)a).CompareTo(b);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Dan Glass
Architect support.com
Australia Australia

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 2 May 2003
Article Copyright 2003 by Dan Glass
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid