Confirm Action

Are you sure you wish to do this?

Confirm Cancel
Member Login

Site Notices
11/20/2019 5:07:11 PM
Posted: 11/2/2004 2:34:44 PM EST
Anyone here good with Visual Basic.NET ???

I am trying to make a program with a listbox of all 50 states.

Then when the user starts typing the beginning letters of the state into a textbox, the state will be highlighted in the listbox when enough letters have been typed.

Any Ideas???

Link Posted: 11/2/2004 2:40:19 PM EST
Auto fill in is probably just a property of the textbox.

If I remember tomorrow I'll look it up for you.
Link Posted: 11/2/2004 2:42:30 PM EST
too many beers right now to write that out for ya
Link Posted: 11/2/2004 2:42:38 PM EST
Friends don't let friends program in VB.
Link Posted: 11/2/2004 2:50:00 PM EST
if you cant find it on google it isnt possiblehave
good luck
Link Posted: 11/2/2004 2:51:20 PM EST
ok I will search the google empire of info.


Link Posted: 11/2/2004 3:44:15 PM EST
[Last Edit: 11/2/2004 3:57:34 PM EST by LightningLink]
With a VB6 ListBox and ComboBox, all you have to do is set the Sorted property to True and it will allow you to select by type-matching. Perhaps the .NET ListBox works the same?


EDIT: just realized you are typing in a TextBox, and not the ListBox. Again, in VB6, I know exactly how to do this. For example:

Private Sub txtStateName_KeyPress(KeyAscii As Integer)

strBuffer = txtStateName.Text
lngRetVal = SendMessage(lstStateList.hWnd, CB_FINDSTRING, -1, ByVal strBuffer)
If lngRetVal <> CB_ERR Then
lstStateList.ListIndex = lngRetVal
KeyAscii = 0
End If

End Sub

Basically, ListBoxes and ComboBoxes support a FindString function, but it is not exposed to VB. The SendMessage is a Windows API call that does the same thing returning the index of the first item that matches. The above code searches the lstStateList ListBox for whatever you've typed and selects the appropriate item if it matches.

The trick would be to see if the .NET ListBox supports a similar feature to search the list for a partial match. Worst case would simply be to trap the TextBox change event and manually search the ListBox looking for a match. Basically "For Loop" through the state ListBox and when you find one that partially matches the typed text, select that list index. Although I've taken a VB.NET class and could figure it out, I don't have it installed at home to tinker with it. I'm still a VB6 guy because I fear change

Good luck!
Link Posted: 11/2/2004 4:18:27 PM EST
I won't get into the specifics, but the .NET ListBox supports a FindString method that will return the index of the first item that matches the typed string. You can then set the SelectedIndex to that return value and it should select the appropriate state. You can put code in the TextBox's TextChanged event to do the search. The simple code looks like:

Dim x As Integer = -1
x = ListBox1.FindString(TextBox1.Text, x)
If x <> -1 Then ListBox1.SelectedIndex = x

Top Top