|
-
Oct 18th, 2006, 09:11 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Checking listview subitem(1) for certain text
i have tried everything and cannot get this to work. what i am looking to do is check all the items in the listview (subitem(1)) to see if a certain text string exists. if the string exists, then to not allow the closing of the app.
this is what i have, any idea?
i am getting argument not optional on highlighted.
VB Code:
Private Sub mnuFileMenuExit_Click()
If lvwUserPunchedOut.ListItems[hl].Item[/hl] = "N/A - New Employee" Then
MsgBox "You cannot close " & Me.Caption & vbNewLine & _
"because some users have never punched in or out yet.", _
vbExclamation, "New Users Present."
Exit Sub
Else
Unload Me
End If
End Sub
-
Oct 18th, 2006, 09:12 PM
#2
Re: Checking listview subitem(1) for certain text
For the first listitem...
VB Code:
lvwUserPunchedOut.ListItems(1).SubItems(1)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 18th, 2006, 09:15 PM
#3
Thread Starter
PowerPoster
Re: Checking listview subitem(1) for certain text
 Originally Posted by RobDog888
For the first listitem...
VB Code:
lvwUserPunchedOut.ListItems(1).SubItems(1)

updated post #1 and got something else. hehe
now what if i want to check all rows in the listview? i would loop through?
-
Oct 18th, 2006, 09:20 PM
#4
Thread Starter
PowerPoster
Re: Checking listview subitem(1) for certain text
ok, this is what i have so far and its working, but is there a better way to do it?
VB Code:
Private Sub mnuFileMenuExit_Click()
m_lngN = 0
If lvwUserPunchedOut.ListItems(m_lngN + 1).SubItems(m_lngN + 1) = "N/A - New Employee" Then
MsgBox "You cannot close " & Me.Caption & vbNewLine & _
"because some users have never punched in or out yet.", _
vbExclamation, "New Users Present."
Exit Sub
Else
Unload Me
End If
End Sub
-
Oct 18th, 2006, 09:22 PM
#5
Re: Checking listview subitem(1) for certain text
Yes, you can use the .FindItem passing the lvwSubItem constant
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 18th, 2006, 09:33 PM
#6
Thread Starter
PowerPoster
Re: Checking listview subitem(1) for certain text
 Originally Posted by RobDog888
Yes, you can use the .FindItem passing the lvwSubItem constant
.FindItem only allows you to pass one criteria right? would this go through all the rows to check each one or would i still have to loop through each row of the information?
-
Oct 18th, 2006, 10:44 PM
#7
Re: Checking listview subitem(1) for certain text
You don't need to loop with .FindItem ...
But if I'm not mistaken, it does not work properly on subitems on one of the match values; either whole or partial, forgot on which it fails.
Try FindItem first... if it does not return a listitem object from a subitem match when it should then you'll have to resort to looping.
-
Oct 18th, 2006, 10:49 PM
#8
Thread Starter
PowerPoster
Re: Checking listview subitem(1) for certain text
 Originally Posted by leinad31
You don't need to loop with .FindItem ...
But if I'm not mistaken, it does not work properly on subitems on one of the match values; either whole or partial, forgot on which it fails.
Try FindItem first... if it does not return a listitem object from a subitem match when it should then you'll have to resort to looping.
am i looping in post #4? not sure what im doing there haha
-
Oct 18th, 2006, 11:07 PM
#9
Re: Checking listview subitem(1) for certain text
VB Code:
Dim cntA As Long
Dim cntB As Long
Dim bFound As Boolean
bFound = False
For cntA = 1 To lvwUserPunchedOut.ListItems.Count
For cntB = 1 To lvwUserPunchedOut.ColumnHeaders.Count -1 'since .ListSubItems might not be initialized
If StrComp(lvwUserPunchedOut.ListItems(cntA).SubItems(cntB), "N/A - New Employee", vbTextCompare) = 0 Then
bFound = True
Exit For
End If
Next
If bFound = True Then Exit For
Next
If "N/A - New Employee" is always written to a subitem index, or a particular column, then you don't need the nested loop for subitem iteration, you'll just loop through the listitems.
-
Oct 18th, 2006, 11:09 PM
#10
Re: Checking listview subitem(1) for certain text
 Originally Posted by BrailleSchool
ok, this is what i have so far and its working, but is there a better way to do it?
VB Code:
Private Sub mnuFileMenuExit_Click()
m_lngN = 0
If lvwUserPunchedOut.ListItems(m_lngN + 1).SubItems(m_lngN + 1) = "N/A - New Employee" Then
MsgBox "You cannot close " & Me.Caption & vbNewLine & _
"because some users have never punched in or out yet.", _
vbExclamation, "New Users Present."
Exit Sub
Else
Unload Me
End If
End Sub
I don't see a loop anywhere...
Looks like you're just checking the first sub item of the first list item.
-
Oct 18th, 2006, 11:59 PM
#11
Re: Checking listview subitem(1) for certain text
 Originally Posted by leinad31
You don't need to loop with .FindItem ...
But if I'm not mistaken, it does not work properly on subitems on one of the match values; either whole or partial, forgot on which it fails.
Try FindItem first... if it does not return a listitem object from a subitem match when it should then you'll have to resort to looping.
I have not heard or experienced this. Passing the lvwSubitem with the lvwPartial or lvwWholeWord.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 19th, 2006, 12:52 AM
#12
Re: Checking listview subitem(1) for certain text
VB Code:
Private Sub Command1_Click()
Dim lstFound As ListItem
ListView1.ListItems(1).Selected = True
'============
Set lstFound = ListView1.FindItem("Text 3", lvwSubItem, , lvwPartial)
If lstFound Is Nothing Then
Debug.Print ".FindItem(""Text 3"", lvwSubItem, , lvwPartial) Is Nothing"
Else
Debug.Print ".FindItem(""Text 3"", lvwSubItem, , lvwPartial) SUCCESS"
lstFound.Selected = True
lstFound.EnsureVisible
End If
'============
Set lstFound = ListView1.FindItem("Text 3", lvwSubItem, , lvwWhole)
If lstFound Is Nothing Then
Debug.Print ".FindItem(""Text 3"", lvwSubItem, , lvwWhole) Is Nothing"
Else
Debug.Print ".FindItem(""Text 3"", lvwSubItem, , lvwWhole) SUCCESS"
lstFound.Selected = True
lstFound.EnsureVisible
End If
'============
Set lstFound = ListView1.FindItem("Text 3 Sub 2", lvwSubItem, , lvwPartial)
If lstFound Is Nothing Then
Debug.Print ".FindItem(""Text 3 Sub 2"", lvwSubItem, , lvwPartial) Is Nothing"
Else
Debug.Print ".FindItem(""Text 3 Sub 2"", lvwSubItem, , lvwPartial) SUCCESS"
lstFound.Selected = True
lstFound.EnsureVisible
End If
'============
Set lstFound = ListView1.FindItem("Text 3 Sub 2", lvwSubItem, , lvwWhole)
If lstFound Is Nothing Then
Debug.Print ".FindItem(""Text 3 Sub 2"", lvwSubItem, , lvwWhole) Is Nothing"
Else
Debug.Print ".FindItem(""Text 3 Sub 2"", lvwSubItem, , lvwWhole) SUCCESS"
lstFound.Selected = True
lstFound.EnsureVisible
End If
End Sub
Private Sub Form_Load()
Dim lstNew As ListItem
Dim iA As Integer
Dim iB As Integer
With ListView1
.FullRowSelect = True
.HideColumnHeaders = False
.LabelEdit = lvwManual
.MultiSelect = False
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Text"
.ColumnHeaders.Add , , "SubItem(1)"
.ColumnHeaders.Add , , "SubItem(2)"
.ColumnHeaders.Add , , "SubItem(3)"
.ColumnHeaders.Add , , "SubItem(4)"
.ColumnHeaders.Add , , "SubItem(5)"
.ColumnHeaders.Add , , "SubItem(6)"
.ListItems.Clear
For iA = 1 To 10
Set lstNew = .ListItems.Add
lstNew.Text = "Text " & iA
For iB = 1 To .ColumnHeaders.Count - 1
.ListItems(iA).SubItems(iB) = lstNew.Text & " Sub " & iB
Next
Next
End With
Set lstNew = Nothing
End Sub
Please verify my code and test result
.FindItem("Text 3", lvwSubItem, , lvwPartial) Is Nothing
.FindItem("Text 3", lvwSubItem, , lvwWhole) Is Nothing
.FindItem("Text 3 Sub 2", lvwSubItem, , lvwPartial) SUCCESS
.FindItem("Text 3 Sub 2", lvwSubItem, , lvwWhole) SUCCESS
My result is that finditem on subitem, only works when the search string supplied matches the full text in the subitem regardless of lvwPartial or lvwWhole. A truly partial search does not work.
Maybe your using an API solution? Does the API solution exhibit the same problem or works as intended?
-
Oct 19th, 2006, 02:59 AM
#13
Re: Checking listview subitem(1) for certain text
Braille, since your seem to be searching for the full text you can use finditem
VB Code:
Private Sub mnuFileMenuExit_Click()
Dim lstFound as ListItem
Set lstFound = lvwUserPunchedOut.FindItem("N/A - New Employee", lvwSubItem, , lvwWhole)
If Not (lstFound Is Nothing) Then
MsgBox "You cannot close " & Me.Caption & vbNewLine & _
"because some users have never punched in or out yet.", _
vbExclamation, "New Users Present."
Exit Sub
Else
Unload Me
End If
End Sub
-
Oct 19th, 2006, 11:04 PM
#14
Thread Starter
PowerPoster
Re: Checking listview subitem(1) for certain text
thanks for all the help guys. everything is working so far and not finding any bugs to squash.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|