一、解析 FpSpread1_UpdateCommand
1.触发时机:表单内容改动后,当用户点击 CommandBar Update 按钮时将会触发。
2.事件分析:UpdateCommand 事件。触发事件次数以更改行数为基准。例如我们更改了两行那么该事件将会触发两次。事件触发一次 e.EditValues 中将包含当前行被编辑的元素。同时,e.EditValues 中元素的个数代表当前表单有多少列。
通过截图看触发过程:
3.我们能从 FpSpread1_UpdateCommand 事件参数 SpreadCommandEventArgs e 中获取哪些信息。请参考代码:
protected void FpSpread1_UpdateCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
//取得事件名称
string commandName = e.CommandName;
//取得当前操作表单
FarPoint.Web.Spread.SheetView currentSheet = e.SheetView;
//取得编辑
ArrayList editValues = e.EditValues;
//获取当前 Update 列
int currentCol;
//通过判断当前元素类型获取当前列
for (int i = 0; i < editValues.Count; i++)
{
if (editValues[i] is string)
{
currentCol = i;
}
}
//通过 CommandArgument 获取当前行
int currentRow = (int)(e.CommandArgument);
}
、ComboBoxCellType 时,会触发 ButtonCommand 事件。
2.事件分析:有很多用户都会问,ButtonCellType、ComboBoxCellType 是否有后台事件?Spread 下 ButtonCommand 即为相应以上两种单元格点击的后台事件。
3.下面我们来看看在这个事件中我们可以获取那些信息。参开代码:
protected void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
//获取当前操作的Spread,从而可以获取当前 Spread 的任何信息
FarPoint.Web.Spread.FpSpread currentSpread = (FarPoint.Web.Spread.FpSpread)(sender);
//取得事件名称
string commandName = e.CommandName;
//取得当前操作表单
FarPoint.Web.Spread.SheetView currentSheetView = e.SheetView;
//
Point cellIndex = (Point)e.CommandArgument;
int row = cellIndex.X;
int col = cellIndex.Y;
}
复制代码
环境:VS2010 && Spread for .NET 6