Link to home
Start Free TrialLog in
Avatar of ELSJE
ELSJE

asked on

AUTOCOMPLETING A DATACOMBOBOX/ SORT ALPHABETICALLY

DOES SOMEBODY KNOW HOW TO MAKE ,WHEN THE USER STARTS TO TYPE IN A DATACOMBOBOX, THAT THE FIRTST MATCHING ITEM IN THE LIST APPEARS AUTOMATICALLY? I KNOW THAT IT CAN WORK WITH A NORMAL COMBOBOX, BUT CAN THIS ALSO BE DONE WITH A DATACOMBO???

FURTHERMORE, HOW CAN I MAKE THE ITEMS OF THE LIST IN A COMBOBOX APPEAR IN ALPHABETICAL ORDER. RIGHT NOW I AM DOING THIS WHEN I AM CREATING THE CONNECTIONS OF MY DATAENVIRONMENT (USING SQL). BUT THIS MAKES THAT WHENEVER I AM DOING AN UPDATE IN A FORM, BASED ON A SORTED DATAMEMBER, THE NEW REGISTER IMMEDIATELY ENTERS IN THE ALPHABETICAL ORDER. SO THE USER CAN'T SEE ANYMORE WHAT HE JUST UPDATED.


THANKS FOR YOUR HELP
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Hi ELSJE,

Try this auto-complete sample, i don't know if it works too in datacombo, if not working please inform me, thanks.

Here is the code:

'Combo - Using the auto-complete function
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const CB_FINDSTRING = &H14C
Private Const CB_ERR = (-1)
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_SETCURSEL = &H14E
Private m_bEditFromCode As Boolean
Private Sub Form_Load()
    With Combo1
      .AddItem "VB Square"
      .AddItem "http://www.vbsquare.com"
      .AddItem "VB World"
      .AddItem "http://www.vb-world.net"
    End With
End Sub
Private Sub Combo1_Change()
    Dim i As Long, j As Long
    Dim strPartial As String, strTotal As String
    If m_bEditFromCode Then
        m_bEditFromCode = False
        Exit Sub
    End If
    With Combo1
        strPartial = .Text
        i = SendMessage(.hwnd, CB_FINDSTRING, -1, ByVal strPartial)
        If i <> CB_ERR Then
            strTotal = .List(i)
            j = Len(strTotal) - Len(strPartial)
            If j <> 0 Then
                m_bEditFromCode = True
                .SelText = Right$(strTotal, j)
                'Select unmatched characters
                .SelStart = Len(strPartial)
                .SelLength = j
            End If
        End If
    End With
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyDelete
      m_bEditFromCode = True
    Case vbKeyBack
      m_bEditFromCode = True
    End Select
End Sub

'Hope will help.
Avatar of ELSJE
ELSJE

ASKER

Sorry ryancys, this doesn't work at all.
it starts to give the error on .list
I guess this would be working perfectly with a normal combobox, but with datacombo it doesn't function.

els
Hi ELSJE, thanks to inform me that. Maybe i shall try myself later.
Avatar of ELSJE

ASKER

Hi ryancys, I would be very thankful if you could keep me informed. Unfortunately this is a question that has been asked before by other persons, but nobody seems to know a solution to this problem.

els
did you try with mtchentry property?
Avatar of ELSJE

ASKER

Hi Richie,

I tried this,I changed the property from 1 to 0 and back. I tried also various styles of comboboxes, but without the desired result.

els
I can't post MSDN article cause it is in spanish, but do a search in MSDN that comming with Visual studio for:
MatchEntry (property).
It appears to be what you are looking for.
Avatar of ELSJE

ASKER

THANKS RICHIE I WILL LOOK, BUT DON'T WORRY I DO SPEAK SPANISH FLUENTLY.
I WILL LOOK ON THE INTERNET IF I CAN FIND IT BECAUSE I DON'T HAVE MSDN INSTALLED. ESPERO QUE LO PUEDO ENCONTRAR!!

ELS
Could you please turn caps off.
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way, MSDN is on net, in Microsoft site.
One more thing.
Try not to use binded controls, populate it manually.
You could use a standard combo and use the code posted by ryancys.
Avatar of ELSJE

ASKER

Hi Richie,
dblextendedmatching in matchentry and dbcdropdownlist in style gives me more or less what I want. Could be better though

I know how to populate the combo when working with dao. For a lot of reasons I used this time a dataenvironment and unfortunately I don't see how to access the indexes .... when using this.

Thanks

els