I need to find if in first column and second column is present a value.
I need to loop the item in listview or?
for example for first column Myvar="test"
for example for first column Myvar1="test1"
LISTVIEW FIND
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: LISTVIEW FIND
For example:
Code: Select all
Dim MyVar As String
Dim MyVar1 As String
Dim itm As MSComctlLib.ListItem
Dim idx As Long
MyVar = "test"
MyVar1 = "test1"
idx = 1
With Me.ListView1
Do
Set itm = .FindItem(sz:=MyVar, Index:=idx)
If itm Is Nothing Then Exit Do
If itm.ListSubItems(1).Text = MyVar1 Then
f = True
Exit Do
End If
idx = itm.Index + 1
Loop Until idx > .ListItems.Count
End With
If itm Is Nothing Then
MsgBox "Not found!"
Else
MsgBox "Found in item #" & itm.Index
End If
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36
Re: LISTVIEW FIND
HansV wrote: ↑20 Mar 2022, 10:28For example:
Code: Select all
Dim MyVar As String Dim MyVar1 As String Dim itm As MSComctlLib.ListItem Dim idx As Long MyVar = "test" MyVar1 = "test1" idx = 1 With Me.ListView1 Do Set itm = .FindItem(sz:=MyVar, Index:=idx) If itm Is Nothing Then Exit Do If itm.ListSubItems(1).Text = MyVar1 Then f = True Exit Do End If idx = itm.Index + 1 Loop Until idx > .ListItems.Count End With If itm Is Nothing Then MsgBox "Not found!" Else MsgBox "Found in item #" & itm.Index End If
OPS...
dim f as Boolean...
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: LISTVIEW FIND
Thanks, It should be
Code: Select all
Private Sub CommandButton2_Click()
Dim MyVar As String
Dim MyVar1 As String
Dim itm As MSComctlLib.ListItem
Dim f As Boolean
Dim idx As Long
MyVar = "That"
MyVar1 = "test1"
idx = 1
With Me.ListView1
Do
Set itm = .FindItem(sz:=MyVar, Index:=idx)
If itm Is Nothing Then Exit Do
If itm.ListSubItems(1).Text = MyVar1 Then
f = True
Exit Do
End If
idx = itm.Index + 1
Loop Until idx > .ListItems.Count
End With
If f = False Then
MsgBox "Not found!"
Else
MsgBox "Found in item #" & itm.Index
End If
End Sub
Best wishes,
Hans
Hans