ListView控件记录定位(与数据表无关)
各位朋友:
请教一下,我想定位ListView控件指定记录该属性是哪一个?
如我要定位到编号为001的记录,我希望能够自动选中该条记录并加亮显示(该定位与数据表无关,仅仅是ListView控件显示时的定位),请知情的朋友指点一下,谢谢!
[解决办法]
Option Explicit
Private Sub Form_Load()
Dim lvi As ListItem
Dim s As Variant
With ListView1
.Checkboxes = True
.FullRowSelect = True
.MultiSelect = True
.View = lvwReport
.HideSelection = True
.ColumnHeaders.Add , , "Name "
.ListItems.Add , , "A "
.ListItems.Add , , "B "
.ListItems.Add , , "C "
.ListItems.Add , , "D "
For Each s In Array( "A ", "C ", "E ")
Set lvi = .FindItem(s, lvwText, , lvwPartial)
If Not lvi Is Nothing Then
lvi.Selected = True
lvi.Checked = True
End If
Next
End With
End Sub
[解决办法]
Dim xItem As ListItem
Dim b As Boolean
'失去焦点的时候不要隐藏选择
ListView1.HideSelection = False
b = False
'遍历查找
For Each xItem In ListView1.ListItems
If xItem.Text = "001 " Then
'找到了需要的项目
b = True
xItem.Selected = True '设置选中
xItem.Checked = True '设置打勾
Exit For
End If
Next
If Not b Then MsgBox "没有找到001 "