How to search a Listview past the first colum

DaveMon

New member
Joined
Oct 13, 2005
Messages
4
Programming Experience
5-10
Hello All, I have found several snipetts of code to search a Listview but they all seem to only search the first column. Has anyone seen a way to search the 2nd 3rd etc. columns data? Heres what I have so far


Code:

'in LVvb.vb class file
' See LVFindTest for parm definitions
PublicSub LVFnd(ByRef lv As ListView, ByVal ss AsString, _
OptionalByVal flag AsInteger = LVFI_PARTIAL)
Dim xFindInfo As LVFINDINFO = New LVFINDINFO
xFindInfo.flags = Convert.ToUInt32(flag)
xFindInfo.psz = ss
Dim index AsInteger = SendMessage(lv.Handle, Convert.ToUInt32(LVM_FINDITEM), -1, xFindInfo)
If index > -1 Then
lv.Items(index).Selected = True
lv.Items(index).Focused = True
EndIf
EndSub
' See LVFindTest for parm definitions
PublicFunction GetSubItemRect(ByRef lv As ListView, ByVal iItem AsInteger, _
ByVal sItem AsInteger, OptionalByVal flag AsInteger = LVIR_BOUNDS) As Rectangle
Dim lpRect As RECT = New RECT
With lpRect
.top = sItem : .left = flag
Dim result AsInteger = SendMessage(lv.Handle, Convert.ToUInt32(LVM_GETSUBITEMRECT), iItem, lpRect)
If result = 0 Then
ReturnNew Rectangle(0, 0, 0, 0)
Else
Return Rectangle.FromLTRB(.left, .top, .right, .bottom)
EndIf
EndWith
EndFunction

''' In Button3 Click Event

Dim fPar AsInteger = Lvfind.LVFindItem.LVFI_PARTIAL
' Clear any selection in the ListView control
' ClearSelection()
' Make an instance of the LVFindItem class
Dim lvf AsNew LVFind.LVFindItem
' Call the LVFnd() sub
' 1st parm is ListView control
' 2nd parm is text to find
' 3rd parm is flag value (see LVFind class for definition)
lvf.LVFnd(ListView1, TextBox5.Text, fPar)
' Focus the ListView control so we can see which item is selected
ListView1.Focus()

Again I can only search the first colum of data.......... need to search the 3rd column actually. Thanks in advance


Dave
 
I figured it out...heres what I wanted

Public Function FindSubItem(ByVal list As ListView, ByVal index As Integer, ByVal text As String) As Integer
Dim x As Integer ' number of index in Listview1
Dim yn As Boolean ' boolean to determine if item is found in Listview
Dim q As String ' my atttept to get the Quan dynamically
For Each item As ListViewItem In list.Items
' MsgBox(text)
' MsgBox(item.SubItems(index).Text)
yn = False '' reset to false each time when searching for the item
If item.SubItems(index).Text = text Then
x = item.Index
'' MsgBox(x)
Beep() '' good beep will go here
q = item.SubItems(index - 1).Text() '' this gets the quantity of the correct line
' MsgBox(q) '' show me the quantity
item.SubItems(index - 1).Text = q - 1 '' de-increments the quantity in the listview
If q = 1 Then
ListView1.Items(x).Selected() = True '' select the row we are talking about
ListView1.Items(x).Remove() ' remove item with 0 quantity
Exit Function
End If
yn = True ' we found the item in question
ListView1.Items(x).Selected() = True '' select the row we are talking about
ListView1.Focus() ' make sure we can see that row
Return item.Index
End If
Next
If yn = False Then
'' bad beep code goes here
Sound.PlayWaveFile("bad.wav")
MsgBox((text) & " ITEM IS NOT ON THIS INVOICE !!! ")
End If
End Function
 
Back
Top