Farpoint Spread 控件自带了很多类型的单元格(日期,数字,下拉列表等等),可是没有一个控件支持多选,
为了现实以上效果,其间也想了不少办法,重绘继承单元格,最后效果都不理想,
最后,通过网上的资料,知道还有一种手段,那就是在单元格里面嵌入自定义控件,这个自定义控件还 必须继承IEmbeddedControlSupport(命名空间FarPoint.Win.Spread.DrawingSpace)接口,并实现接口方法
主要代码如下:
public partial class SpreadComboCheckBoxList : ComboCheckBoxList, IEmbeddedControlSupport
{
public SpreadComboCheckBoxList()
{
InitializeComponent();
}
public void ControlPaint(Graphics g, Rectangle r, Appearance appearance, object value, bool isSelected, bool isLocked,
float zoomFactor)
{
appearance.ShowActive = true;
appearance.DrawPrimaryButton = true;
g.SetClip(r, CombineMode.Intersect);
}
private Moving _moving = Moving.None;
private Sizing _sizing = Sizing.None;
private const ChildActivationPolicy Activation = ChildActivationPolicy.Click;
public virtual ChildActivationPolicy ActivationPolicy
{
get
{
return Activation;
}
set
{
}
}
public virtual Moving CanMove
{
get
{
return _moving;
}
set
{
_moving = value;
}
}
public virtual Sizing CanSize
{
get
{
return _sizing;
}
set
{
_sizing = value;
}
}
}
最后在FpSpread中加入这个控件
//实例化自定义控件
var spComboCheckBox = new SpreadComboCheckBoxList
{
Name = cell.Row.Index + "_" + cell.Column.Index + "_" + "SpreadComboCheckBoxList"
};
//将自定义控件加入指定位置的单元格
FpSpread.Sheets[0].AddControl(spComboCheckBox,cell.Row.Index, cell.Column.Index);