Solved

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

Posted on 2003-11-12
11
248 Views
Last Modified: 2010-05-03
How do i search for an item in the second, or third column of a listview.
0
Comment
Question by:malavan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
11 Comments
 

Author Comment

by:malavan
ID: 9730333
How do i search for an item in the second, or third column of a listview.
0
 
LVL 9

Expert Comment

by:p_sie
ID: 9730379
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.
0
 
LVL 9

Expert Comment

by:p_sie
ID: 9787347
Did this help you in any way?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:p_sie
ID: 9817014
If not let me know
0
 
LVL 9

Expert Comment

by:p_sie
ID: 9857176
Do you need more info?
0
 

Author Comment

by:malavan
ID: 9857225
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.
0
 
LVL 9

Expert Comment

by:p_sie
ID: 9857284
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
0
 
LVL 9

Accepted Solution

by:
p_sie earned 25 total points
ID: 9940567
malavan,

is this question still open? I am just checking questions that I participated in and that were not closed yet!

Greetings, p_sie
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10537297
Moderator, my recommended disposition is:

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

Dan Rollins -- EE database cleanup volunteer
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question