using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace WindowsFormsApplication1{ public partial class Form1 : Form { [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { listView1.Items.Add("111"); listView1.Items.Add("222"); listView1.Items.Add("333"); listView1.EnableItem(listView1.Items[2], false); listView1.Items.Add("444"); listView1.EnableItem(listView1.Items[3], false); listView1.Items.Add("555"); listView1.EnableItem(listView1.Items[4], false); listView1.Items.Add("666"); listView1.Items.Add("777"); listView1.Items.Add("888"); } } public class ExListView : ListView { Dictionary_maskCheckBoxList; public ExListView() { _maskCheckBoxList = new Dictionary (); } public void EnableItem(ListViewItem item,bool isEnable) { if (!isEnable) { CheckBox cb = new CheckBox() { Text = item.Text }; cb.Enabled = false; this.Controls.Add(cb); _maskCheckBoxList.Add(item.Index, cb); } else { this.Controls.Remove(_maskCheckBoxList[item.Index]); _maskCheckBoxList.Remove(item.Index); } } protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x000F: if (View != View.Details) break; foreach (int index in _maskCheckBoxList.Keys) { Rectangle rect = Items[index].GetBounds(ItemBoundsPortion.Entire); //adjust rect.Y += 1; rect.X += 6; _maskCheckBoxList[index].Bounds = rect; if ((this.HeaderStyle != ColumnHeaderStyle.None) && (rect.Top < Font.Height)) { _maskCheckBoxList[index].Visible = false; continue; } else { _maskCheckBoxList[index].Visible = true; } } break; } base.WndProc(ref m); } }}