大致意思如下:
一个窗体中有3个控件:
1.tvwList [TreeView ]
2.cmdCancel [CommandButton]
3.txtName [Textbox ]
需要如下效果,
当文本框txtName中输入的值非法时,单击tvwList中的节点无效,但是可以使用cmdCancel取消输入.
请问该如何实现以上效果?
但是如果是下面这样的话,虽然tvwList获取不到,但是cmdCancel也不能使用啊!
Code:
Private Sub txtName_Validate(Cancel As Boolean)
txtName=trim(txtName)
if txtName="" or not isnumeric(txtname) then
msgbox "输入值不能为空或数字,请重新输入!"
Cancel=true
endif
End sub
哪位大侠帮解决一下?
Private Sub txtName_Validate(Cancel As Boolean)
txtName=trim(txtName)
if txtName="" or not isnumeric(txtname) then
msgbox "输入值不能为空或数字,请重新输入!"
treeview1.enabled=false
else
treeview1.enabled=true
endif
End sub
当然,如果你可能有别的控件需要cmdCancel.causesvalidation=true,那么可以在txtname获取焦点时
将cmdcancel设为false,失去焦点在将其设为True
Private Sub txtName_GotFocus()
tvwList.CausesValidation = True
cmdCancel.CausesValidation = False
End Sub
Private Sub txtName_LostFocus()
tvwList.CausesValidation = True
cmdCancel.CausesValidation = True
End Sub