先上效果图

1, 先写一个 GridCheckMarksSelection 类
class GridCheckMarksSelection
{
#region Fileds
RepositoryItemGridLookUpEdit _currentRepository;
protected ArrayList selection;
protected String checkColumnFieldName = "CheckMarkSelection";
RepositoryItemCheckEdit edit;
const Int32 CheckboxIndent = 4;
#endregion
#region Construct
public GridCheckMarksSelection(RepositoryItemGridLookUpEdit repository)
: this()
{
CurrentRepository = repository;
}
public RepositoryItemGridLookUpEdit CurrentRepository
{
get { return _currentRepository; }
set
{
if (_currentRepository != value)
{
Detach();
Attach(value);
}
}
}
public GridCheckMarksSelection()
{
selection = new ArrayList();
this.OnSelectionChanged();
}
#endregion
#region Attribute
public ArrayList Selection
{
get { return selection; }
set { selection = value; }
}
public Int32 SelectedCount { get { return selection.Count; } }
#endregion
#region GridSelect
public object GetSelectedRow(Int32 index)
{ return selection[index]; }
public Int32 GetSelectedIndex(object row)
{ return selection.IndexOf(row); }
public void ClearSelection(GridView currentView)
{
selection.Clear();
Invalidate(currentView);
OnSelectionChanged();
}
public void SelectAll(object sourceObject)
{
selection.Clear();
if (sourceObject != null)
{
if (sourceObject is ICollection)
selection.AddRange(((ICollection)sourceObject));
else
{
GridView currentView = sourceObject as GridView;
for (Int32 i = 0; i < currentView.DataRowCount; i++)
selection.Add(currentView.GetRow(i));
Invalidate(currentView);
}
}
this.OnSelectionChanged();
}
public delegate void SelectionChangedEventHandler(object sender, EventArgs e);
public event SelectionChangedEventHandler SelectionChanged;
public void OnSelectionChanged()
{
if (SelectionChanged != null)
{
EventArgs e = new EventArgs();
SelectionChanged(this, e);
}
}
public void SelectGroup(GridView currentView, Int32 rowHandle, bool select)
{
if (IsGroupRowSelected(currentView, rowHandle) && select) return;
for (Int32 i = 0; i < currentView.GetChildRowCount(rowHandle); i++)
{
Int32 childRowHandle = currentView.GetChildRowHandle(rowHandle, i);
if (currentView.IsGroupRow(childRowHandle))
SelectGroup(currentView, childRowHandle, select);
else
SelectRow(currentView, childRowHandle, select, false);
}
Invalidate(currentView);
}
public void SelectRow(GridView currentView, Int32 rowHandle, bool select)
{
SelectRow(currentView, rowHandle, select, true);
}
public void InvertRowSelection(GridView currentView, Int32 rowHandle)
{
if (currentView.IsDataRow(rowHandle))
SelectRow(currentView, rowHandle, !IsRowSelected(currentView, rowHandle));
if (currentView.IsGroupRow(rowHandle))
SelectGroup(currentView, rowHandle, !IsGroupRowSelected(currentView, rowHandle));
}
public bool IsGroupRowSelected(GridView currentView, Int32 rowHandle)
{