【发布时间】:2010-11-26 21:36:19
【问题描述】:
Public Sub subkeydown(txt As TextBox, lst As ListBox, KeyCode As Integer)
On Error Resume Next
lstfstrec = True
If txt.Text = "" Then lst.Visible = False: Exit Sub
If KeyCode = 40 Then
lst.Selected(lst.ListIndex + 1) = True ': Exit Sub
'MsgBox lstMedicine.ListIndex
End If
If KeyCode = 38 Then lst.Selected(lst.ListIndex - 1) = True ': Exit Sub
End Sub
我的项目中有一个名为 subkeydown() 的函数(见上文),当用户按下向上箭头或向下箭头键时会调用该函数。调用该函数时,会触发 ListBox 的单击事件。 ListBox 包含药品名称并绑定到数据库,因此我想在用户单击 ListBox 时调用 Click 事件但不是自动的。
【问题讨论】:
-
您不必自己选择列表项 - 向上箭头和向下箭头将更改列表框的选择,并为您处理溢出/下溢,只要它具有焦点。这实际上是一个焦点问题吗?