?
Solved

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

Posted on 2003-11-12
11
Medium Priority
?
259 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 100 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

771 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