Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Aug 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combobox refresh problem (VB6)

    Hi All,

    After creating my own Entrymatch on a combobox I encountered the following problem. The first time I enter a character in my combobox, I get all the matching results as expected. As the matching results narrow down as I enter more characters the length of the dropdownlist gets less then the default length. When this happens you will be able to see the previous results below the new ones. It looks like the window doesn't refresh as it supposed to do. The included printscreen will make this problem more clear.
    I hope someone knows the answer.
    Thanks in advance.

    Jevis

    Code used:

    Option Explicit

    Private Const WM_SETREDRAW = &HB
    Private Const CB_SHOWDROPDOWN = &H14F

    Private rsDropDownList As Recordset
    Private strZoekstring As String
    Private strTextCache As String
    Private blnSkipChange As Boolean

    Private Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Long) As Long

    Private Sub cboOntvanger_GotFocus()
    Dim lreturn As Long
    If cboOntvanger.Text = "" Then
    GetRecords "AfzenderOntvanger", "*", "Naam", ""
    LoadDropDownList cboOntvanger, rsDropDownList, "", "Naam", 1
    End If
    lreturn = SendMessage(cboOntvanger.hwnd, CB_SHOWDROPDOWN, True, 0&)

    End Sub

    Private Sub cboOntvanger_LostFocus()
    Dim lreturn As Long
    lreturn = SendMessage(cboOntvanger.hwnd, CB_SHOWDROPDOWN, False, 0&)
    End Sub

    Private Sub Form_Initialize()
    End Sub

    Private Sub cboAfzender_Change()
    strZoekstring = "Naam LIKE '" + cboAfzender.Text + "%'"
    GetRecords "AfzenderOntvanger", "Naam", "Naam", strZoekstring
    End Sub

    Private Sub cboOntvanger_KeyUp(KeyCode As Integer, Shift As Integer)
    Dim lreturn As Long

    If KeyCode = 13 Then
    SendKeys "{TAB}"
    Else
    strZoekstring = "Naam LIKE '" + Trim(cboOntvanger.Text) + "%'"

    If Trim(cboOntvanger.Text) <> "" Then
    strTextCache = Trim(cboOntvanger.Text)
    cboOntvanger.Clear
    GetRecords "AfzenderOntvanger", "Naam", "Naam", strZoekstring
    LoadDropDownList cboOntvanger, rsDropDownList, strZoekstring, "Naam", 0
    Else
    strTextCache = ""
    cboOntvanger.Clear
    GetRecords "AfzenderOntvanger", "*", "Naam", ""
    LoadDropDownList cboOntvanger, rsDropDownList, "", "Naam", 1
    End If
    lreturn = SendMessage(frmTest.hwnd, WM_SETREDRAW, True, 0&)
    End If
    End Sub

    Sub GetRecords(strTabel As String, strSelectColumn As String, strOrderColumn As String, strCriteria As String)

    Set rsDropDownList = New Recordset

    With rsDropDownList
    .CursorType = adOpenKeyset
    .LockType = adLockReadOnly
    .Open "SELECT " & strSelectColumn & _
    " FROM " & strTabel & _
    " ORDER BY " & strOrderColumn, conActief
    End With

    End Sub

    Sub LoadDropDownList(vcboCombo As ComboBox, vrsRecordSet As Recordset, strCriteria As String, strFieldname As String, intSearchOrFull As Integer)
    Dim strEntry As String
    Dim intIndex As Integer
    Dim lreturn As Long

    intIndex = 0

    With vrsRecordSet

    'Halt repaint
    lreturn = SendMessage(vcboCombo.hwnd, WM_SETREDRAW, False, 0&)

    Select Case intSearchOrFull
    Case 0
    vcboCombo.AddItem vcboCombo.Text, intIndex
    intIndex = intIndex + 1

    .Find strCriteria, adSearchForward

    If Not .EOF Then
    Do While Not .EOF
    strEntry = Trim(.Fields(strFieldname).Value)
    vcboCombo.AddItem strEntry, intIndex
    intIndex = intIndex + 1
    .Find strCriteria, 1, adSearchForward
    Loop
    End If
    Case 1
    .MoveFirst
    If Not .EOF Then
    Do While Not .EOF
    strEntry = Trim(.Fields(strFieldname).Value)
    vcboCombo.AddItem strEntry, intIndex
    intIndex = intIndex + 1
    .MoveNext
    Loop
    End If
    End Select

    'Start repaint
    lreturn = SendMessage(vcboCombo.hwnd, WM_SETREDRAW, True, 0&)

    vcboCombo.Text = strTextCache
    vcboCombo.SelStart = Len(vcboCombo)
    .Close
    End With

    Set vrsRecordSet = Nothing

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Combobox refresh problem (VB6)

    Could this be a problem with your video card? The code clears the combo box in the KeyUp event, so old entries shouldn't remain. I copied your code and adapted it only where needed to refer to my test database; the list part of the combo box grows and shrinks as needed.
    (One minor point: the code doesn't seem to like Backspace)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •