Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 8th, 2005, 7:54 PM   #1
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
how to make an autocompleting combobox?

ok here's the scenario:

a combobox has a set list of entries. if a user comes along and starts typing something into the text field of the combobox, is there any simple way to fill in the rest of the box with something that already exists in the combobox?

example:

the contents of the combobox are <bacala, bacon, bananas, brew>. the user types "baca" and an "la" should get appended to the current text, but the "la" should be highlighted so that if bacala is not the word the user wants, they can continue to type straight over it. the user types "ban" and "anas" gets appended. if the user types "bac" then nothing gets appended because there are multiple possibilities.

i'm not asking for someone to code such a routine and do the work for me, rather, i'm just asking if there's a combobox flag or a vb control or something i'm overlooking that would enable such a function

thanks
chepfaust is offline   Reply With Quote
Old Mar 10th, 2005, 3:28 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
This'll do paths and URLs, but if you want something different, you'll just have to code it as there is no built-in function to do the windows auto-complete on anything else.
Add a text box to a form and put this in it
Private Const SHACF_AUTOAPPEND_FORCE_OFF = &H80000000
Private Const SHACF_AUTOAPPEND_FORCE_ON = &H40000000
Private Const SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000
Private Const SHACF_AUTOSUGGEST_FORCE_ON = &H10000000
Private Const SHACF_DEFAULT = &H0
Private Const SHACF_FILESYSTEM = &H1
Private Const SHACF_URLHISTORY = &H2
Private Const SHACF_URLMRU = &H4
Private Const SHACF_USETAB = &H8
Private Const SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)
Private Declare Sub SHAutoComplete Lib "shlwapi.dll" (ByVal hwndEdit As Long, ByVal dwFlags As Long)
Private Sub Form_Load()
    SHAutoComplete Text1.hWnd, SHACF_DEFAULT
End Sub
Rory is offline   Reply With Quote
Old Mar 10th, 2005, 7:43 PM   #3
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Quote:
Originally Posted by Rory
This'll do paths and URLs, but if you want something different, you'll just have to code it as there is no built-in function to do the windows auto-complete on anything else.
hmm paths and urls are not what i had in mind so i guess i'll have to code it, but thanks for answering my question.
chepfaust is offline   Reply With Quote
Old Mar 14th, 2005, 3:19 PM   #4
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Ok No Problem. You should be able to find something ready made and stable on PSC (planetsourcecode.com).
Rory is offline   Reply With Quote
Old Mar 30th, 2005, 10:58 PM   #5
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Dim i As Integer
Dim OriginalTextLength As Integer
If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Or KeyCode = vbKeyShift Or _
    KeyCode = vbKeyHome Or KeyCode = vbKeySpace Or txtKw(Index).Text = "" Then Exit Sub
For i = 0 To lsKw(Index).ListCount - 1
    If LCase(txtKw(Index).Text) = LCase(Left(lsKw(Index).List(i), Len(txtKw(Index).Text))) Then
        OriginalTextLength = Len(txtKw(Index).Text)
        txtKw(Index).Text = lsKw(Index).List(i)
        txtKw(Index).SelStart = OriginalTextLength
        txtKw(Index).SelLength = Len(txtKw(Index).Text) - OriginalTextLength
        Exit For
    End If
Next i

ok i hackneyed this off some random site i came across and modified it to suit my own purposes.

i'm having a slight problem with it. it works great for the most part, but if the user types too fast then it makes a huge textual mess.

example: "praga khan" "pringles" "proton" are three words in a listbox. if i start typing "programming" at my normal speed, the routine will assume i'm typing "proton" and will append and highlight "ton" so i can type over it if necessary. except i'm typing faster than the routine can highlight the new suggestion, so i would end up with something like "protongramming."

aside from not typing so fast, what is an efficient way that i can put in a delay or something to prevent it from coming up with a suggestion so quickly?
chepfaust is offline   Reply With Quote
Old Apr 2nd, 2005, 10:07 PM   #6
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
It wouldn't take much modification to make it display the autocomplete in a tooltip, or a floating label just below the textbox like in Word. Then if the user types to quickly, the problem wouldn't happen. To actually autocomplete, the user would press enter, i.e. you'd just add something like If KeyCode = vbKeyReturn then txtThisBox.Text = lblTooltip.Caption
Similarly you could write a textbox usercontrol that achieved the same effect as the original (displaying the new text as a selection) but double buffering the text so that the garbling wouldn't occur.
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC