以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]KEYDOWN事件!  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=95252)

--  作者:xietan417
--  发布时间:2017/1/14 11:35:00
--  [求助]KEYDOWN事件!
Dim n As WinForm.ComboBox = e.Form.Controls("ComboBox1")
Dim b As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim nt As WinForm.Label = e.Form.Controls("Label1")
Dim nt1 As WinForm.Label = e.Form.Controls("Label2")
If e.keycode = Keys.Enter   Then
    Dim dr As DataRow
    dr = DataTables("门店明细").Find("条形码 = \'" & b.value & "\' and 门店 = \'" & n.value & "\' ")
    If dr IsNot Nothing Then
        dr("tem") = 1
    Else
        MessageBox.Show("条码不存在或者门店不相符")
    End If
    e.cancel = True
    Select Case str(0)
End Select
b.Value = ""
End If

我在textbox的keydown事件里写这个代码居然还是跳到  MessageBox.Show("条码不存在或者门店不相符") 这行代码去!
但是做了一个button 去掉keycode 的部份代码却能正常判断!看不出来有什么差别啊!

--  作者:有点蓝
--  发布时间:2017/1/14 11:51:00
--  
button代码是怎样的?

上面代码如果能查到数据肯定不会跳到MessageBox

--  作者:xietan417
--  发布时间:2017/1/14 11:55:00
--  
一样的!就是少一个KEYCODE
Dim n As WinForm.ComboBox = e.Form.Controls("ComboBox1")
Dim b As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim nt As WinForm.Label = e.Form.Controls("Label1")
Dim nt1 As WinForm.Label = e.Form.Controls("Label2")

  If b.text = "" Then
e.cancel = True

Else
   Dim dr As DataRow
   dr = DataTables("门店明细").Find("条形码 = \'" & b.value & "\' and 门店 = \'" & n.value & "\' ")
   If dr IsNot Nothing Then
     dr("tem") = 1
   Else
   MessageBox.Show("条码不存在或者门店不相符")
   End If

    e.cancel = True
    Select Case str(0)
End Select
b.Value = ""
End If


--  作者:有点蓝
--  发布时间:2017/1/14 12:01:00
--  
b.value改为b.text试试

另外按钮里使用e.cancel没有意义

--  作者:xietan417
--  发布时间:2017/1/14 12:03:00
--  
我知道!我已经试了!果然是这个问题!晕死!
--  作者:xietan417
--  发布时间:2017/1/14 12:05:00
--  
求科普一下原因!我拆开代码做测试!为什么text 可以value 不行?影响因素是什么?
--  作者:有点蓝
--  发布时间:2017/1/14 14:07:00
--  
焦点离开文本框后text 的值才会写入value 
--  作者:xietan417
--  发布时间:2017/1/14 15:46:00
--  
哦!学习了!图片点击可在新窗口打开查看