现在有一个leavecell事件,判断格内值不符合要求就取消离开。
点击按钮会保存表中的值并关闭窗口。
我找到了点击按钮后调用leavecell事件的办法,但传的值不正确。
有很多因为执行顺序需要修改的,所以不能用别的办法,要考虑复用性和冲突,会更复杂。
代码大概是这样,设置完后除了一堆的问题。首先leave的方法在点击时就发生了,但并没有跑过entercell,不知为什么会这样。第二e.canncel不能正确执行
leave方法我希望如果值为0或与其他值相同,就把值设为0并取消离开动作。
Public Sub FpSpread1_LeaveCell(ByVal sender As Object, ByVal e As LeaveCellEventArgs) Handles SPR_KoumokuEdit.LeaveCell
Dim spread As TsSpread = Me.SPR_KoumokuEdit
Dim sheet As FarPoint.Win.Spread.SheetView = spread.ActiveSheet
For i As Integer = sheet.FrozenRowCount To sheet.RowCount - 1
If i <> sheet.ActiveRowIndex Then
If sheet.Cells(i, 8).Value = sheet.Cells(sheet.ActiveRowIndex, 8).Value Or sheet.Cells(sheet.ActiveRowIndex, 8).Value = 0 Then
sheet.Cells(e.Row, 8).Value = 0
e.Cancel = True
Exit For
End If
End If
Next
End Sub
Protected Overrides Sub GcShpBtn_OK_Click(sender As Object, e As EventArgs)
'Dim spread1 As TsSpread = Me.SPR_KoumokuEdit
'Dim ss1 As FarPoint.Win.Spread.SpreadView = spread1.GetRootWorkbook
'Dim instance As New LeaveCellEventArgs(ss1, enterRow, enterCol, enterRow + 1, enterCol)
'执行LeaveCell
'FpSpread1_LeaveCell(spread1, instance)
上传数据库
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
在进入cell时设行列数值
Private Sub SPR_KoumokuEdit_EnterCell(sender As Object, e As EnterCellEventArgs) Handles SPR_KoumokuEdit.EnterCell
enterRow = e.Row
enterCol = e.Column
End Sub |