Home > Archive > Visual Basic > May 2004 > ** VB HELP ** select listItems in a listview using searchcriteria
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
** VB HELP ** select listItems in a listview using searchcriteria
|
|
| farmer 2004-05-27, 4:31 pm |
|
Hi,
I'v got the folowing problem.
I've made a VB programm to work with several workbooks and worksheets.
At one particular time the user can make a selection of what he or
she wants to copy or whatever. For this purpose I use 2 optionbuttons
and a textbox
The user can fill the textbox with a particular (search)string to find
and select the workbooks or sheets he/she wants. With the two
optionbuttons it is possible to search either at the beginning or at
the end of a name.
I use the folowing code:
Private Sub option_Click()
For Each listitem In ListView1.ListItems
listitem.Checked = False
Next
For r = 1 To ListView1.ListItems.Count - 1
If Option1.Value = True Then
If Left(ListView1.ListItems(r), Len(Text1)) = Text1 Then
ListView1.ListItems(r).Checked = True
End If
Else
If Option2.Value = True Then
If Right(ListView1.ListItems(r), Len(Text1)) = Text1 Then
ListView1.ListItems(r).Checked = True
End If
End If
End If
Next r
End Sub
In most cases the code works just fine. However, when the item is not
selected in situations when it is also the last item in the listview.
What's wrong with the code ???
Help appreciated,
Farmer
| |
| Ken Halter 2004-05-27, 5:30 pm |
| farmer wrote:
> Hi,
>
>
> What's wrong with the code ???
<snip>
> For r = 1 To ListView1.ListItems.Count - 1
Get rid of the -1 at the end of the line above. ListItems is a 1 based
collection so they're numbered 1 through ListItems.Count (not 0 through
ListItems.Count - 1)
btw. Have you experimented with the ListView's built in FindItem method?
>
> Help appreciated,
>
> Farmer
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
| |
|
| If you really want to do it the loop way, I suggest you add a little more to it
- check with same case, like
If Lcase(Left(ListView1.ListItems(r)), Len(Text1)) = Lcase(Text1) Then
- or, you can check occurence of text with..
If Instr(1, Lcase(ListView1.ListItems(r)), Lcase(Text1.Text)) > 0 then
It's like using wildcards before and after your search string
Kjell
| |
| farmer 2004-05-28, 3:30 pm |
|
Hi Kjell,
Thanks for the advice for not making it case sensitive. You're code
however isn't working. It should have been:
If LCase(Left(ListView1.ListItems(r), Len(Text1))) = LCase(Text1) Then
btw, you're other code snippet isn't working either.
Greetings Farmer,
On Fri, 28 May 2004 02:16:05 -0700, "Kjell"
<anonymous@discussions.microsoft.com> wrote:
>If you really want to do it the loop way, I suggest you add a little more to it
>
>- check with same case, like
> If Lcase(Left(ListView1.ListItems(r)), Len(Text1)) = Lcase(Text1) Then
>
>- or, you can check occurence of text with..
>
>If Instr(1, Lcase(ListView1.ListItems(r)), Lcase(Text1.Text)) > 0 then
>
>It's like using wildcards before and after your search string
>
>Kjell
|
|
|
|
|