Warning

 

Close

Confirm Action

Are you sure you wish to do this?

Confirm Cancel
BCM
User Panel

Site Notices
Posted: 11/2/2004 3:34:44 PM EDT
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???

Thanks,
Fidel
Out
Link Posted: 11/2/2004 3:40:19 PM EDT
[#1]
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 3:42:30 PM EDT
[#2]
too many beers right now to write that out for ya
Link Posted: 11/2/2004 3:42:38 PM EDT
[#3]
Friends don't let friends program in VB.
Link Posted: 11/2/2004 3:50:00 PM EDT
[#4]
if you cant find it on google it isnt possiblehave
good luck
-derek
Link Posted: 11/2/2004 3:51:20 PM EDT
[#5]
ok I will search the google empire of info.

Thanks

Fidel
Out
Link Posted: 11/2/2004 4:44:15 PM EDT
[#6]
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?

LL

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!
LL
Link Posted: 11/2/2004 5:18:27 PM EDT
[#7]
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


LL
Close Join Our Mail List to Stay Up To Date! Win a FREE Membership!

Sign up for the ARFCOM weekly newsletter and be entered to win a free ARFCOM membership. One new winner* is announced every week!

You will receive an email every Friday morning featuring the latest chatter from the hottest topics, breaking news surrounding legislation, as well as exclusive deals only available to ARFCOM email subscribers.


By signing up you agree to our User Agreement. *Must have a registered ARFCOM account to win.
Top Top