首先将VS的Editable=flexEDNone则所有列不能编辑 在进入某个要编辑的列时将Editable设成可编辑 可在Private Sub VsBDetail_AfterSelChange(ByVal OldRowSel As Long, ByVal OldColSel As Long, ByVal NewRowSel As Long, ByVal NewColSel As Long)事件中通过col值进行判断。 第2问没说清楚。
应该为如下可让某些特定列可编辑 Private Sub fg1_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean) If Row <> 1 Then Cancel = True End If End Sub
我自己已解决了,不过还的感谢大家。 下面把解决思路写下:'修改前看到是否需要修改 Private Sub Grid_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean) 'On Error GoTo err If UiI10101.ValueInt > 2 Then '*************定义允许修改的状态,需修改 Cancel = True Exit Sub End If If Grid.Col = Grid.cols - 8 Or Grid.Col = Grid.cols - 7 Then '*************定义可以修改的列,需修改 Cancel = False '使其有效 Else Cancel = True '使其无效为真 End If Exit Sub Err: RaiseErr "frmY005-Grid_MouseDown()" End Sub '修改后判断是否合法 'cancel=true 取消修改的 Private Sub Grid_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean) On Error Resume Next If Not IsNumeric(Grid.EditText) Then MsgBox "输入不合法,应输入一个数值", vbInformation, "提示" Cancel = True Exit Sub End If
End Sub'修改后来更改别的一些数据 Private Sub Grid_AfterEdit(ByVal Row As Long, ByVal Col As Long) On Error Resume Next '进货数量=包装数量 * 整装数量 + 零装数量 Grid.TextMatrix(Row, Grid.cols - 6) = Grid.TextMatrix(Row, Grid.cols - 9) * Grid.TextMatrix(Row, Grid.cols - 8) + Grid.TextMatrix(Row, Grid.cols - 7) End Sub
msflexgrid1.row=1
msflexgird1.col=1
msflexgird1.text="记录"
在进入某个要编辑的列时将Editable设成可编辑
可在Private Sub VsBDetail_AfterSelChange(ByVal OldRowSel As Long, ByVal OldColSel As Long, ByVal NewRowSel As Long, ByVal NewColSel As Long)事件中通过col值进行判断。
第2问没说清楚。
Private Sub fg1_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
If Row <> 1 Then
Cancel = True
End If
End Sub
下面把解决思路写下:'修改前看到是否需要修改
Private Sub Grid_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
'On Error GoTo err If UiI10101.ValueInt > 2 Then '*************定义允许修改的状态,需修改
Cancel = True
Exit Sub
End If
If Grid.Col = Grid.cols - 8 Or Grid.Col = Grid.cols - 7 Then '*************定义可以修改的列,需修改
Cancel = False '使其有效
Else
Cancel = True '使其无效为真
End If
Exit Sub
Err:
RaiseErr "frmY005-Grid_MouseDown()"
End Sub
'修改后判断是否合法
'cancel=true 取消修改的
Private Sub Grid_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
On Error Resume Next
If Not IsNumeric(Grid.EditText) Then
MsgBox "输入不合法,应输入一个数值", vbInformation, "提示"
Cancel = True
Exit Sub
End If
End Sub'修改后来更改别的一些数据
Private Sub Grid_AfterEdit(ByVal Row As Long, ByVal Col As Long)
On Error Resume Next
'进货数量=包装数量 * 整装数量 + 零装数量
Grid.TextMatrix(Row, Grid.cols - 6) = Grid.TextMatrix(Row, Grid.cols - 9) * Grid.TextMatrix(Row, Grid.cols - 8) + Grid.TextMatrix(Row, Grid.cols - 7)
End Sub