 |

08-29-2002, 09:13 AM
|
|
|
Help with this bit of code
|
i have a listview and a text box. in the second column of the listview is a number, i want the user to be able to enter a character and the listview to be selected at the first item that matches that character i.e.
user enters 1
1324567 selected
1234567
5678909
i can get this to work. But i want the focus to go back to the textbox whilst the listview remains selected, so the user can keep typing in numbers, i.e.
user then enters 2
1324567
1234567 selected
5678909
but when put focus back to the textbox the listview deselects???
here is what i have:
Private Sub txtID_Change()
Dim i As Long
For i = lstVvideo.ListItems.Count To 0 Step -1
lstVvideo.SetFocus
Set lstVvideo.SelectedItem = lstVvideo.ListItems(i)
If Left$(lstVvideo.SelectedItem.ListSubItems(1).Text, Len(txtID.Text)) = txtID.Text Then
Exit For
End If
Next
|
|

08-29-2002, 09:23 AM
|
 |
Centurion
|
|
Join Date: Aug 2002
Location: Ontario, Canada
Posts: 170
|
|
|
You're asking the program to have focus on two different things. It, like humans, can't.
|
__________________
A silly idea is current that good people do not know what temptation means. This is an obvious lie. Only those who try to resist temptation know how strong it is... A man who gives in to temptation after five minutes simply does not know what it would have been like an hour later. That is why bad people, in one sense, know very little about badness. They have lived a sheltered life by always giving in. -C.S. Lewis
|

08-29-2002, 09:25 AM
|
|
|
|
i suppose another way i can do it is to keep the listview empty and just fill it with anything that matches the textbox, i suppose?
|
|

08-29-2002, 10:04 AM
|
 |
Mexican Coder
|
|
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
|
|
Check this example, I hope help:
Code:
Private Sub Form_Load()
ListView1.ListItems.Add , , 123
ListView1.ListItems.Add , , 234
ListView1.ListItems.Add , , 345
ListView1.ListItems.Add , , 456
ListView1.ListItems.Add , , 567
End Sub
Private Sub Text1_Change()
Dim lstitem As ListItem
For i = 1 To ListView1.ListItems.Count
Set lstitem = ListView1.FindItem(Text1.Text, lvwText, , lvwPartial)
If Not lstitem Is Nothing Then lstitem.Selected = True
Next i
End Sub
Put a Listview (ListView1) and set this property:
- HideSelection = False
- and add 1 column
And put a TextBox (Text1)
|
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
|

08-29-2002, 10:21 AM
|
 |
Algorithms 'R' Us
Forum Leader * Guru *
|
|
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
|
|
I wonder if it's possible that you're misinterpreting the ListView behaviour?
What is the setting of its HideSelection property? If it's true then the selected item is not highlighted unless the LV has the focus... but the selected item is STILL the selected item... if you set HideSelection to False, the item selected will retain its highlight even though focus stays with your textbox...
In either case it shouldn't affect which item is selected, and your method of controlling the listbox selection as described should work with no problems
but usually you'd prefer the new item selected to be visually identifiable
When you change your ListView selected item in response to the TextBox change, it's probably a good idea to use the EnsureVisible method on the new ListItem, so the ListView will automatically show the new selection...
Code:
ListView.SelectedItem.EnsureVisible
Dr Memory 
|
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!
At first, I was iridescent. Then, I became transparent. Finally, I was absent.
|

08-29-2002, 10:34 AM
|
 |
Mexican Coder
|
|
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
|
|
Yes because the listview item list is bigger than the Heigth of the Listview, then the EnsureVisible move the list to allow the listitem selected to be visible
is good !
I put the HideSelection = False to show what Item is currently selected because he do test to my code an this show what item is founding the FindItem Method.

|
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
|

08-29-2002, 12:17 PM
|
 |
Algorithms 'R' Us
Forum Leader * Guru *
|
|
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
|
|
Cheers!
Love your avatar! I always wanted to head up a clothing store called MyCrowSoft Wear, with a big laughing-crow logo (like on Grateful Dead's Wake of the Flood album)
Dr Memory 
|
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!
At first, I was iridescent. Then, I became transparent. Finally, I was absent.
|

08-29-2002, 01:21 PM
|
 |
Mexican Coder
|
|
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
|
|
Thanks, and I like your sign, is good, using vb to say something !!!

|
__________________
Mikecrosoft.NET
* If I stop to ask I will stop to learn
* Just I know that I don't know nothing
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|