using System;
using System.Data;
using System.Text;
using System.Globalization;
using System.Collections;
using System.Reflection;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Runtime.InteropServices;
namespace CommonFrame.OCX
{
/// <summary>
/// 为ListView增加数据绑定、查找和排序功能
/// </summary>
///
#region 枚举
public enum SortType
{
String,
Number,
Date
}
#endregion
#region 继承实现ListView列表类
public class ListViewEx : System.Windows.Forms.ListView
{
#region 列表项目所需的WIndows32 API定义
[StructLayout(LayoutKind.Sequential)]
private struct HDITEM
{
public Int32 mask;
public Int32 cxy;
[MarshalAs(UnmanagedType.LPTStr)]
public String pszText;
public IntPtr hbm;
public Int32 cchTextMax;
public Int32 fmt;
public Int32 lParam;
public Int32 iImage;
public Int32 iOrder;
};
[StructLayout(LayoutKind.Sequential) ]
public struct LVFINDINFO
{
public LVFI_FLAGS flags;
public string psz;
public IntPtr lParam;
public Point pt;
public VirtualKey vkDirection ;
}
public enum LVFI_FLAGS
{
LVFI_PARAM = 0x1,
LVFI_PARTIAL = 0x8,
LVFI_STRING = 0x2,
LVFI_WRAP = 0x20,
LVFI_NEARESTXY = 0x40,
}
public enum VirtualKey
{
VK_LEFT = 0x25,
VK_RIGHT = 0x27,
VK_UP = 0x26,
VK_DOWN = 0x28,
VK_HOME = 0x24,
VK_END = 0x23,
VK_PRIOR = 0x21,
VK_NEXT = 0x22
}
[DllImport("user32")]
static extern IntPtr SendMessage(IntPtr Handle, Int32 msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32", EntryPoint="SendMessage")]
static extern IntPtr SendMessageH(IntPtr Handle, Int32 msg, IntPtr wParam, ref HDITEM lParam);
[DllImport("user32.dll", EntryPoint="SendMessage", CharSet=CharSet.Auto)]
static extern int SendMessageL(System.IntPtr hWnd, Int32 msg, int wParam, ref LVFINDINFO lparam);
const Int32 HDI_WIDTH = 0x0001;
const Int32 HDI_HEIGHT = HDI_WIDTH;
const Int32 HDI_TEXT = 0x0002;
const Int32 HDI_FORMAT = 0x0004;
const Int32 HDI_LPARAM = 0x0008;
const Int32 HDI_BITMAP = 0x0010;
const Int32 HDI_IMAGE = 0x0020;
const Int32 HDI_DI_SETITEM = 0x0040;
const Int32 HDI_ORDER = 0x0080;
const Int32 HDI_FILTER = 0x0100; // 0x0500
const Int32 HDF_LEFT = 0x0000;
const Int32 HDF_RIGHT = 0x0001;
const Int32 HDF_CENTER = 0x0002;
const Int32 HDF_JUSTIFYMASK = 0x0003;
const Int32 HDF_RTLREADING = 0x0004;
const Int32 HDF_OWNERDRAW = 0x8000;
const Int32 HDF_STRING = 0x4000;
const Int32 HDF_BITMAP = 0x2000;
const Int32 HDF_BITMAP_ON_RIGHT = 0x1000;
const Int32 HDF_IMAGE = 0x0800;
const Int32 HDF_SORTUP = 0x0400; // 0x0501
const Int32 HDF_SORTDOWN = 0x0200; // 0x0501
const Int32 LVM_FIRST = 0x1000; // List 消息
const Int32 LVM_FINDITEMA = LVM_FIRST + 13;
const Int32 LVM_FINDITEMW = LVM_FIRST + 83;
const Int32 LVM_GETHEADER = LVM_FIRST + 31;
const Int32 HDM_FIRST = 0x1200; // Header 消息
const Int32 HDM_SETIMAGELIST = HDM_FIRST + 8;
const Int32 HDM_GETIMAGELIST = HDM_FIRST + 9;
const Int32