0
我在窗体中有一个列表框。点击它会导致表单跳转到另一条记录。它应该突出显示一个项目并跳转到正确的记录。相反,它会突出显示并立即清除选择,尽管它仍会跳转到记录中。当我使用标准记录选择按钮时,项目被正确突出显示。列表框项目在点击时没有突出显示
我从.ListIndex属性读取所选项目的索引,因为当我测试选择哪个项目时,Selected()在单选模式下不起作用。但是,.ListIndex是只读属性,我使用.Selected()突出显示该项目。
干杯!
编辑:下面的代码:
Option Compare Database
Option Explicit
Private Sub Form_Current()
Call highlightListBox
End Sub
Private Sub lbListBox_Click()
Dim rs As DAO.Recordset
Dim indx As Long
Set rs = Me.RecordsetClone
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
rs.FindFirst "[ID]=" & CStr(Me.lbListBox.ItemData(Me.lbListBox.ListIndex))
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
End If
rs.Close
Set rs = Nothing
End Sub
Private Sub highlightListBox()
Dim lngIndx As Long
Dim lngI As Long
Dim bNoMatch As Boolean
lngIndx = 0
bNoMatch = True
If Me.NewRecord <> 0 Or IsNull(Me!ID) Then
For lngI = 0 To Me.lbListBox.ListCount - 1
Me.lbListBox.Selected(lngI) = False
Next lngI
Else
Do
lngIndx = lngIndx + 1
If CLng(Me.lbListBox.ItemData(lngIndx - 1)) = Me!ID Then
bNoMatch = False
End If
Loop Until CLng(Me.lbListBox.ItemData(lngIndx - 1)) = Me!ID Or lngIndx = Me.lbListBox.ListCount
End If
If Not bNoMatch Then
Me.lbListBox.Selected(lngIndx - 1) = True
End If
End Sub
a会发现一个SSCCE有用... –
我只是试图解释这个问题。希望这看起来更好 – Celdor