Click here to Skip to main content
15,892,537 members
Articles / Multimedia / GDI+

A Bindable, Sortable, Autosizing ListView

Rate me:
Please Sign up or sign in to vote.
4.44/5 (8 votes)
16 May 2005CPOL3 min read 103.7K   1.3K   86  
A listview with support for Databinding, Sorting & Autofit and upon rebinding data reselection of a previous selected item
/**
 * @Name ListViewDoubleSorter.cs
 * @Purpose Sorting for doubles
 * @Date 19 April 2005, 08:06:45
 * @Author S.Deckers 
 * @Description
 */
 
namespace Whoua.Src.Sorting
{
	#region -- Using directives --
	using System;
	using System.Windows.Forms;
	using d = System.Diagnostics.Debug;
	#endregion

	/// <summary date="18-04-2005, 08:04:33" author="S.Deckers">
	/// Implements sorting for the 'double'-type
	/// </summary>
	class ListViewDoubleSorter : ListViewSorter
	{
		/// <summary>
		/// Sorting
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <returns></returns>
		public override int OnSort(object x, object y, System.Windows.Forms.SortOrder sortOrder)
		{
			System.Windows.Forms.ListViewItem.ListViewSubItem left  = GetLeft( x);
			System.Windows.Forms.ListViewItem.ListViewSubItem right = GetLeft( y);

			int res = HandleEmptyStrings( left, right, sortOrder);

			if( res != 0)
			{
				return( res);
			}

			Double result = Double.Parse( left.Text) - Double.Parse( right.Text);

			if( result > 0)
			{
				res = 1;
			}

			else if( result < 0)
			{
				res = -1;
			}

			else
			{
				res = 0;
			}

			if( sortOrder == SortOrder.Descending)
			{
				res *= -1;
			}

			return( res);
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Merkator
Netherlands Netherlands
Busy with Intergraph G/Technology-GIS

Comments and Discussions