Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Help with this bit of code


Reply
 
Thread Tools Display Modes
  #1  
Old 08-29-2002, 09:13 AM
vilanova
Guest
 
Posts: n/a
Default 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
Reply With Quote
  #2  
Old 08-29-2002, 09:23 AM
MarkVB6's Avatar
MarkVB6 MarkVB6 is offline
Centurion
 
Join Date: Aug 2002
Location: Ontario, Canada
Posts: 170
Default

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
Reply With Quote
  #3  
Old 08-29-2002, 09:25 AM
vilanova
Guest
 
Posts: n/a
Default

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?
Reply With Quote
  #4  
Old 08-29-2002, 10:04 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

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
Reply With Quote
  #5  
Old 08-29-2002, 10:21 AM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

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.
Reply With Quote
  #6  
Old 08-29-2002, 10:34 AM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

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
Reply With Quote
  #7  
Old 08-29-2002, 12:17 PM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

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.
Reply With Quote
  #8  
Old 08-29-2002, 01:21 PM
Mikecrosoft's Avatar
Mikecrosoft Mikecrosoft is offline
Mexican Coder
 
Join Date: Jun 2002
Location: Monterrey, N.L., Mexico
Posts: 2,793
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->