1.创建子编辑器,该编辑器可以创建一个form,然后设计好form界面,并编写相应代码。
2.创建子编辑器类
public class mySubEdit : Form1, FarPoint.Win.Spread.CellType.ISubEditor
{
public event EventHandler ValueChanged;
public event EventHandler CloseUp;
public Form1 frm;
public mySubEdit_GoodsChice()
{
this.View1.DoubleClick += new EventHandler(View1_DoubleClick);
}
private void View1_DoubleClick(object sender, EventArgs e)
{
if (this.View1.Rows.Count > 0)
{
if (ValueChanged != null)
ValueChanged(this, EventArgs.Empty);
if (CloseUp != null)
CloseUp(this, EventArgs.Empty);
}
}
public Point GetLocation(Rectangle rect)
{
Point pt = new Point(0);
Size sz = GetPreferredSize();
pt.Y = 0;// (Screen.PrimaryScreen.WorkingArea.Height / 2) - (sz.Height / 2);
pt.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) - (sz.Width / 2);
return pt;
}
public Control GetSubEditorControl()
{
return this;
}
public object GetValue()
{
return "1,一达软件"; //
}
public void SetValue(object value)
{
// value = "";
}
public Size GetPreferredSize()
{
return new Size(this.Width, Screen.PrimaryScreen.WorkingArea.Height);
}
}
3.在Form_Load事件对fpSpread进行初始化设置
fpSpread1.HorizontalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.AsNeeded;//只有当需要的时候才显示水平滚动条
fpSpread1.VerticalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.AsNeeded; //只有当需要的时候才显示垂直滚动条
fpSpread1.ActiveSheet.GrayAreaBackColor = Color.White; //整个sheet表的背景设置成白色
fpSpread1.ActiveSheet.ColumnCount = 2;
fpSpread1.ActiveSheet.Rows.Count = 10;
fpSpread1.ActiveSheet.Columns[0].Visible = false;
fpSpread1.ActiveSheet.ColumnHeader.Columns[0].Label = "存酒名称";
fpSpread1.ActiveSheet.ColumnHeader.Columns[1].Label = "存酒数量";
fpSpread1.ActiveSheet.Columns[0].Width = 200;
fpSpread1.ActiveSheet.Columns[1].Width = 100;
FarPoint.Win.Spread.CellType.NumberCellType NumberCellType = new FarPoint.Win.Spread.CellType.NumberCellType();
NumberCellType.DecimalPlaces = 1;
fpSpread1.ActiveSheet.Columns[1].CellType = NumberCellType;
FarPoint.Win.Spread.CellType.TextCellType TextCellType = new FarPoint.Win.Spread.CellType.TextCellType();
mySubEdit subEditor = new mySubEdit();
TextCellType.SubEditor = subEditor;
fpSpread1.ActiveSheet.Columns[0].CellType = TextCellType;
编写fspRead的以下两个事件代码:
private void fpSpread1_EditModeOn(object sender, EventArgs e)
{
if (fpSpread1.ActiveSheet.ActiveCell.Column.Index == 1)
{
FarPoint.Win.Spread.CellType.GeneralEditor c = this.fpSpread1.EditingControl as FarPoint.Win.Spread.CellType.GeneralEditor;
c.ButtonStyle =FarPoint.Win.ButtonStyle.PopUp; //用于显示...效果的按钮
}
}
private void fpSpread1_SubEditorClosed(object sender, FarPoint.Win.Spread.SubEditorClosedEventArgs e)
{
//当子编辑器被关闭时,将子编辑器的Text属性值拆分数组,并分别绑定到单元格的Text和Value属性
string[] arr = e.EditingControl.Text.ToString().Split(',');
fpSpread1.ActiveSheet.ActiveCell.Value = arr[0];
fpSpread1.ActiveSheet.ActiveCell.Text = arr[1];
}
Ok,Enjoy it.