|
-
Jun 15th, 2002, 12:09 AM
#1
Thread Starter
Hyperactive Member
Changing Code?
Does anybody know how to adapt this Code to a "listview box"?
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If InStr(1, Left(List1.List(i), Len(Text1.Text)), Text1.Text, vbTextCompare) Then List1.Selected(i) = True: Exit For
Next
End Sub
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 15th, 2002, 06:26 AM
#2
Frenzied Member
I haven't tested this, so it could be a little wrong, but try this:
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 0 To ListView1.ListItems.Count - 1
If InStr(1, Left(ListView.ListItems(i).Caption, Len(Text1.Text)), Text1.Text, vbTextCompare) Then ListView.ListItems(i).Selected = True: Exit For
Next
End Sub
-
Jun 15th, 2002, 08:30 PM
#3
Thread Starter
Hyperactive Member
Dude, that's almost exactly what I tryed.
VB Code:
Dim i As Integer
For i = 1 To ListView1.ListItems.Count
If InStr(1, Left(ListView1.ListItems(i).Text, Len(Text1.Text)), Text1.Text, vbTextCompare) Then ListView1.ListItems(i).Selected = True: Exit For
Next
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 15th, 2002, 08:58 PM
#4
PowerPoster
Well, "new to vb6" I haven't looked at the specifics of RickBull's post, but your response is stunning. "Almost exactly the same" counts in horseshoes and hand grenades, but not in programming.
If you don't understand that even a single comma can totally change what a program does, you should probably look for another line of work.
-
Jun 15th, 2002, 09:01 PM
#5
The picture isn't missing
maybe if you looked at their codes, phinds, you would notice that the only difference is Caption and Text, and i dont think that a listview would have a caption property ...... dont criticize people
also the 0 and 1 difference but eh.......
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 15th, 2002, 09:13 PM
#6
Thread Starter
Hyperactive Member
ListView doesn't have a Caption property and if I use 0 I get an invalid index error, so I used 1 and that got rid of the error.
The only this is that when I type in some text Nothing happens.
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 15th, 2002, 09:55 PM
#7
PowerPoster
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 1 To Listview1.ListCount
If InStr(1, Left(Listview1.List(i), Len(Text1.Text)), Text1.Text, Listview1.ListItems(i)) Then
Listview1.ListItems(i).Selected = True
Exit For
Next
End Sub
That should do it.
Just remember that for the common controls, all arrays are indexed from 1, not 0, as with the standard controls.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jun 15th, 2002, 09:56 PM
#8
PowerPoster
Originally posted by phinds
Well, "new to vb6" I haven't looked at the specifics of RickBull's post, but your response is stunning. "Almost exactly the same" counts in horseshoes and hand grenades, but not in programming.
If you don't understand that even a single comma can totally change what a program does, you should probably look for another line of work.
That sort of comment is pretty unnecessary.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Jun 15th, 2002, 10:37 PM
#9
Thread Starter
Hyperactive Member
[QUOTE]Originally posted by rjlohan
[B]
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 1 To Listview1.ListCount
If InStr(1, Left(Listview1.List(i), Len(Text1.Text)), Text1.Text, Listview1.ListItems(i)) Then
Listview1.ListItems(i).Selected = True
Exit For
Next
End Sub
ListView doesn't have a list or listcount property. Will this work?
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 15th, 2002, 10:50 PM
#10
The picture isn't missing
listview1.listitems.count
or
listview1.listitems.listcount
its one of them. cant remember
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 15th, 2002, 11:18 PM
#11
Thread Starter
Hyperactive Member
Originally posted by rjlohan
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 1 To Listview1.ListCount
If InStr(1, Left(Listview1.List(i), Len(Text1.Text)), Text1.Text, Listview1.ListItems(i)) Then
Listview1.ListItems(i).Selected = True
Exit For
Next
End Sub
When I try it your way and change it to the way BuggyProgrammer showed I get an error "Next without For" and when I try
VB Code:
Dim i As Integer
For i = 1 To ListView1.ListItems.Count
If InStr(1, Left(ListView1.ListItems(i), Len(Text1.Text)), Text1.Text, ListView1.ListItems(i)) Then ListView1.ListItems(i).Selected = True: Exit For
Next
I get a "Type mismatch" error
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 15th, 2002, 11:24 PM
#12
The picture isn't missing
he forgot the End If
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 1 To Listview1.ListCount
If InStr(1, Left(Listview1.List(i), Len(Text1.Text)), Text1.Text, Listview1.ListItems(i)) Then
Listview1.ListItems(i).Selected = True
Exit For
End If
Next
End Sub
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 15th, 2002, 11:46 PM
#13
Thread Starter
Hyperactive Member
I still get a type mismatch error
VB Code:
For i = 1 To ListView1.ListItems.Count
If InStr(1, Left(ListView1.ListItems(i), Len(Text1.Text)), Text1.Text, ListView1.ListItems(i)) Then
ListView1.ListItems(i).Selected = True
Exit For
End If
Next
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 15th, 2002, 11:57 PM
#14
Thread Starter
Hyperactive Member
Ok Let's get out stories straight...
Some of this isn't nedded. I was working on a list box because I was told to use one by someone else.
I thought ListView was better when I found out that ListView Used keys.
Let's work one either the list box or the listview.
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 16th, 2002, 12:22 AM
#15
The picture isn't missing
nothing to do till soccer(or football ) comes on so ill test and fix it for you.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 16th, 2002, 12:29 AM
#16
The picture isn't missing
man whoever typed this before was really bad at this stuff
VB Code:
Dim i As Integer
For i = 1 To ListView1.ListItems.Count
If InStr(ListView1.ListItems(i), Text1.Text) > 0 Then ListView1.ListItems(i).Selected = True: Exit For
Next
the problem was in the Instr, which for some funny reason did something so screwy it cannot be described, other than the person who wrote this code.
and you also dont need the left() part, unless you could tell me why
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 16th, 2002, 01:02 AM
#17
Thread Starter
Hyperactive Member
MidgetsBro originly wrote:
VB Code:
Private Sub Text1_Change()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If InStr(1, Left(List1.List(i), Len(Text1.Text)), Text1.Text, vbTextCompare) Then List1.Selected(i) = True: Exit For
Next
End Sub
for a list box control
See this Thread
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 16th, 2002, 01:04 AM
#18
Thread Starter
Hyperactive Member
I don't care about the code, I just want to compare the text in Text1 to the text in the ListView Control.
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 16th, 2002, 02:26 AM
#19
The picture isn't missing
well does my code wrok for you?
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 16th, 2002, 04:25 AM
#20
Thread Starter
Hyperactive Member
Yes and No
Yes it works as far as no error msg.
No it doesn't retrieve the listview item...
[VBCODE]
Option Explicit
Dim XXX As Porn
Dim Wife As Nag
Private Sub *****_Resize()
On Error Resume Next
Get Viagra
End Sub
[/VBCODE]
-
Jun 16th, 2002, 11:38 AM
#21
The picture isn't missing
did you try setting focus to the listview? because it wont seem to highlight anything if it doesnt.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jun 16th, 2002, 02:16 PM
#22
Hyperactive Member
This code will compare the text in Text1 to the ListView and select the
first listview item that matches. Place a textbox (Text1), a command
button (Command1) and a listview (ListView1) on a form and paste
this code.
Code:
Private Sub Form_Load()
'***************************************
'fill your list here
'***************************************
Text1.Text = ""
Text1.TabIndex = 0
Command1.Default = True
End Sub
Private Sub Command1_Click()
Dim liFound As ListItem ' FoundItem variable.
Set liFound = ListView1.FindItem(Text1, , , lvwPartial)
If liFound Is Nothing Then 'no match
MsgBox "No match found"
Exit Sub
Else 'at least a partial match
liFound.EnsureVisible ' Scroll ListView to show found ListItem.
Set ListView1.SelectedItem = liFound 'select the ListItem
'or you could use this line
'liFound.Selected = True ' Select the ListItem.
ListView1.SetFocus 'keep item selected
End If
End Sub
Private Sub Text1_GotFocus()
If Text1 = "" Then Exit Sub
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
Sometimes what you're looking for is exactly where you left it.
-
Jun 16th, 2002, 02:25 PM
#23
Hyperactive Member
Note: in the above example, a match will only occur if the text matches
the upper most level in the list. To search child levels you must change
Code:
object.FindItem (string, [value], index, match)
[value] to the items level (0 is default). In code you could also cycle through
each level until a match occurs by changing [value] in the finditem string.
Sometimes what you're looking for is exactly where you left it.
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
|