Solved

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

Posted on 2003-11-12
11
227 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
 
LVL 9

Expert Comment

by:p_sie
ID: 9817014
If not let me know
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now