Link to home
Start Free TrialLog in
Avatar of malavan
malavan

asked on

How do i search for an item in the second, or third column of a listview.

How do i search for an item in the second, or third column of a listview.
Avatar of malavan
malavan

ASKER

How do i search for an item in the second, or third column of a listview.
From the MSDN Help File:


use listview1.finditem

--------------------------------------
FindItem Method (ListView Control)
     

Finds and returns a reference to a ListItem object in a ListView control.

Syntax

object.FindItem (string, value, index, match)

The FindItem method syntax has these parts:

Part Description
object Required. An object expression that evaluates to a ListView control.
string Required. A string expression indicating the ListItem object to be found.
value Optional. An integer or constant specifying whether the string will be matched to the ListItem object's Text, Subitems, or Tag property, as described in Settings.
index Optional. An integer or string that uniquely identifies a member of an object collection and specifies the location from which to begin the search. The integer is the value of the Index property; the string is the value of the Key property. If no index is specified, the default is 1.
match Optional. An integer or constant specifying that a match will occur if the item's Text property is the same as the string, as described in Settings.


Settings

The settings for value are:

Constant Value Description
lvwText 0 (Default) Matches the string with a ListItem object's Text property.
lvwSubitem 1 Matches the string with any string in a ListItem object's SubItems property.
lvwTag 2 Matches the string with any ListItem object's Tag property.


The settings for match are:

Constant Value Description
lvwWholeWord 0 (Default) An integer or constant specifying that a match will occur if the item's Text property begins with the whole word being searched. Ignored if the criteria is not text.
lvwPartial 1 An integer or constant specifying that a match will occur if the item's Text property begins with the string being searched. Ignored if the criteria is not text.


Remarks

If you specify Text as the search criteria, you can use lvwPartial so that a match occurs when the ListItem object's Text property begins with the string you are searching for. For example, to find the ListItem whose text is "Autoexec.bat", use:

'Create a ListItem variable.
Dim itmX As ListItem
'Set the variable to the found item.
Set itmX = ListView1.FindItem("Auto",,,lvwpartial)


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
Did this help you in any way?
If not let me know
Do you need more info?
Avatar of malavan

ASKER

i want to search the second or third column of the listview not to search the  string in any of the subitem.( may  be same string present in the 2nd  and 3rd  colum). i need to search in 2nd column only.
please understand my question.
any how thanks for ur response.
Sorry I misunderstood your question

Here is some example code that will search your second column in the listview for the string 'Hello' and highlight the first item
that contains this string.


Dim ColumnYouWantToSearch as Long, SerachString as String

ColumnYouWantToSearch = 1 'notice column = 1 means second column in listview!!!
SearchString = "Hello"

For i =  1 To lst.ListItems.Count
            Set Item = lst.ListItems(i)
            If InStr(1,  Item.ListSubItems(ColumnYouWantToSearch).Text, Searchstring, vbTextCompare) <> 0 Then
                Item.EnsureVisible
                Item.Selected = True
                Exit For
            End If
Next

Good Luck
ASKER CERTIFIED SOLUTION
Avatar of p_sie
p_sie
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DanRollins
Moderator, my recommended disposition is:

    Accept p_sie's comment(s) as an answer.

Dan Rollins -- EE database cleanup volunteer