その他の.Netライブラリ一覧へ戻る
http://blogs.users.gr.jp/naka/category/167.aspx
利用規約
http://blogs.users.gr.jp/naka/articles/2300.aspx
本体
using System;
using System.Collections;
using System.Windows.Forms;
namespace Wankuma.Collections
{
///
/// Stringの正順比較を行います
///
public class ListViewItemStringAscComparer : IComparer
{
private int col;
///
/// カラムを指定しないコンストラクタ
///
public ListViewItemStringAscComparer()
{
col = 0;
}
///
/// カラムを指定したコンストラクタ
///
/// カラム番号
public ListViewItemStringAscComparer(int column)
{
col = column;
}
///
/// 実際の比較処理
///
/// 1個目のListViewItemオブジェクト
/// 2個目のListViewItemオブジェクト
///
/// 2 つの比較対照値の構文上の関係を示す 32 ビット符号付き整数。
/// 値 意味
/// 0より小さい値 x が y より小さい。
/// 0 x と y は等しい。
/// 0より大きい値 x が y より大きい。
///
public int Compare(object x, object y)
{
return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
}
}
///
/// Stringの正順比較を行います
///
public class ListViewItemStringDescComparer : IComparer
{
private int col;
///
/// カラムを指定しないコンストラクタ
///
public ListViewItemStringDescComparer()
{
col = 0;
}
///
/// カラムを指定したコンストラクタ
///
/// カラム番号
public ListViewItemStringDescComparer(int column)
{
col = column;
}
///
/// 実際の比較処理
///
/// 1個目のListViewItemオブジェクト
/// 2個目のListViewItemオブジェクト
///
/// 2 つの比較対照値の構文上の関係を示す 32 ビット符号付き整数。
/// 値 意味
/// 0より小さい値 x が y より大さい。
/// 0 x と y は等しい。
/// 0より大きい値 x が y より小さい。
///
public int Compare(object x, object y)
{
int CompareReturn = String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
return CompareReturn * -1;
}
}
}