Solved

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

Posted on 2003-11-12
11
239 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

776 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