Set ITM = Listview1.FindItem(

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Set ITM = Listview1.FindItem(

Post by sal21 »

Googling...
I need to use the function in object to find MyVar in column 3 of listview1 and return boolean value..
How to?
Tks.

User avatar
HansV
Administrator
Posts: 78483
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set ITM = Listview1.FindItem(

Post by HansV »

Should the text in the column be equal to MyVar, or should it contain MyVar (with possibly other text)?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: Set ITM = Listview1.FindItem(

Post by sal21 »

HansV wrote:Should the text in the column be equal to MyVar, or should it contain MyVar (with possibly other text)?
... i need to find only in column 3 if it contain a MyVar value in any row of column

User avatar
HansV
Administrator
Posts: 78483
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set ITM = Listview1.FindItem(

Post by HansV »

The following will tell you if MyVar is found in any subitem:

Code: Select all

    Dim MyVar As String
    Dim IsFound As Boolean
    MyVar = "..."
    IsFound = Not (Me.ListView1.FindItem(MyVar, lvwSubItem, , False) Is Nothing)
    MsgBox IsFound
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78483
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Set ITM = Listview1.FindItem(

Post by HansV »

And this will tell you if MyVar is found in the 3rd column:

Code: Select all

    Dim MyVar As String
    Dim IsFound As Boolean
    Dim itm As ListItem
    MyVar = "..."
    Set itm = Me.ListView1.FindItem(MyVar, lvwSubItem, , False)
    If Not itm Is Nothing Then
        IsFound = itm.ListSubItems(2).Text = MyVar
    End If
    MsgBox IsFound
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: Set ITM = Listview1.FindItem(

Post by sal21 »

HansV wrote:And this will tell you if MyVar is found in the 3rd column:

Code: Select all

    Dim MyVar As String
    Dim IsFound As Boolean
    Dim itm As ListItem
    MyVar = "..."
    Set itm = Me.ListView1.FindItem(MyVar, lvwSubItem, , False)
    If Not itm Is Nothing Then
        IsFound = itm.ListSubItems(2).Text = MyVar
    End If
    MsgBox IsFound
GREAT!.
TKS