Solved

multi column combobox auto complete

Posted on 2006-07-05
3
560 Views
Last Modified: 2008-01-09
Hi,

I was reviewing the article written on  http://emoreau.s2i.com/ regarding the multicombo box.  I noticed that this control does not have an auto complete feature.  

Does anybody know how difficult it will be to develop the auto complete feature in vb .net 2005 for this control


I found a control www.codeproject.com/vb/net/MultiColumnFlatCombo.asp on this site that has the auto complete feature, and it provides some code on how to implement an auto complete.  But I was hoping to learn how to write the auto complete myself instead of using the control.  If I was restricted to a quick development deadline I would use this control, but since I'm not I rather learn to develop it on my own.  




0
Comment
Question by:foobarr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Assisted Solution

by:carmodyk
carmodyk earned 100 total points
ID: 17042720
I don't know if this will help:

Place this in your Combobox Key_Up function

 Dim cb As ComboBox = CType(sender, ComboBox)
        If Not e.KeyValue = 9 Then
            AutoCompleteKeyUp(cb, e)
        End If

Then this function elsehwere in your project:

Public Sub AutoCompleteKeyUp(ByVal Combo As ComboBox, _
        ByVal e As KeyEventArgs)
        Dim strTyped As String
        Dim intFoundIndex As Integer
        Dim objFoundItem As Object
        Dim strFoundText As String
        Dim strAppendText As String
        ' Ignore basic selection keys
        Select Case e.KeyCode
            Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, _
                Keys.Delete, Keys.Down, Keys.CapsLock
                Return
        End Select
        ' Find what user has typed in list
        strTyped = Combo.Text
        intFoundIndex = Combo.FindString(strTyped)
        ' If found...
        If intFoundIndex >= 0 Then
            ' Get list item (actual type depends on whether data bound)
            objFoundItem = Combo.Items(intFoundIndex)
            ' Use control to resolve text - in case data bound
            strFoundText = Combo.GetItemText(objFoundItem)
            ' Append the typed text to rest of the found string
            ' (text is set twice due to a combo box quirk:
            '  on certain platforms, setting just once ignores casing!)
            strAppendText = strFoundText.Substring(strTyped.Length)
            Combo.Text = strTyped & strAppendText
            ' Select the appended text
            Combo.SelectionStart = strTyped.Length
            Combo.SelectionLength = strAppendText.Length
        End If
    End Sub
0
 
LVL 7

Author Comment

by:foobarr
ID: 17046408
no this is not what i was looking for thanks though!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 400 total points
ID: 17055357
Here is a lot of complex code that I have to implement AutoComplete on any control that you can get the handle to:

'http://63.236.73.220/showthread.php?t=277805

Imports System.Runtime.InteropServices

Public Class AutoComplete
  Implements IDisposable

  ' HKEY_CLASSES_ROOT\Interface\{00000101-0000-0000-C000-000000000046}\IEnumString
  <ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000101-0000-0000-C000-000000000046")> _
  Private Interface IEnumString

    Function [Next](ByVal celt As Integer, ByVal rgelt() As String, ByRef pceltFetched As Integer) As Integer

    Function Skip(ByVal celt As Integer) As Integer

    Function Reset() As Integer

    Sub Clone(ByRef ppenum As IEnumString)

  End Interface   'IEnumString

  <ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("EAC04BC0-3791-11D2-BB95-0060977B464C")> _
  Private Interface IAutoComplete

    Function Init(ByVal hwndEdit As IntPtr, _
     <MarshalAs(UnmanagedType.IUnknown)> ByVal punkACL As Object, _
     ByVal pwszRegKeyPath As String, _
     ByVal pwszQuickComplete As String) As Int32

    ' We must use <PreserveSig()> otherwise after using
    ' autocomplete, fields will not return the next time.

    <PreserveSig()> _
    Function Enable(<[In]()> ByVal fEnable As Boolean) As Boolean

    <PreserveSig()> _
    Function SetOptions(<[In]()> ByVal dwFlag As UInt32) As Integer

    <PreserveSig()> _
    Function GetOptions(<Out()> ByRef pdwFlag As UInt32) As Integer

  End Interface   'IAutoComplete

  Private Enum ShowOptions
    None = 0
    AutoSuggest = &H1
    AutoAppend = &H2
    Search = &H4
    FilterPrefixes = &H8
    UseTab = &H10
    UpDownKeyDropsList = &H20
    RightToLeft = &H40
  End Enum   'ShowOptions

  Private _enabled As Boolean
  Private _autoComp As Type
  Private IAutoComp As IAutoComplete

  Private Class EnumString
    Implements UCOMIEnumString

    ' UCOMIEnumString is the same as the IEnumString interface
    ' see more at Msdn on http://msdn.microsoft.com/library/d...mi_d2l_89uv.asp

    Private _strArray As ArrayList
    Private _pos As Integer = 0

    Public Property Array() As ArrayList
      Get
        Return _strArray
      End Get
      Set(ByVal Value As ArrayList)
        _strArray = Value
      End Set
    End Property    'Array

    Public Function [Next](ByVal celt As Integer, ByVal rgelt As String(), _
     ByRef pceltFetched As Integer) As Integer Implements UCOMIEnumString.Next

      Dim retval As Integer = 1

      pceltFetched = 0
      While Not _pos = _strArray.Count AndAlso Not pceltFetched = celt
        rgelt(pceltFetched) = _strArray(_pos)
        pceltFetched += 1
        _pos += 1
      End While

      If Not pceltFetched.CompareTo(celt) = -1 Then
        retval = 0
      End If

      Return retval

    End Function     'Next

    Public Function Skip(ByVal celt As Integer) As Integer Implements UCOMIEnumString.Skip

      Dim retval As Integer = 1
      _pos += celt

      If Not _pos = _strArray.Count Then
        retval = 0
      End If

      Return retval

    End Function    'Skip

    Public Function Reset() As Integer Implements UCOMIEnumString.Reset

      _pos = 0

      Return _pos

    End Function    'Reset

    Public Sub Clone(ByRef ppenum As UCOMIEnumString) Implements UCOMIEnumString.Clone

      ' create a Clone of this Class
      ppenum = DirectCast(Me, EnumString)

    End Sub    'Clone

  End Class   'EnumString

  Public Sub New(ByVal handleEdit As IntPtr, ByVal listWords As ArrayList, Optional ByVal registryPath As String = "", Optional ByVal quickComplete As String = "")

    Dim iEnumList As New EnumString
    iEnumList.Array = listWords

    _autoComp = Type.GetTypeFromCLSID(New Guid("{00BB2763-6A77-11D0-A535-00C04FD7D062}"))

    IAutoComp = DirectCast(Activator.CreateInstance(_autoComp), _
     IAutoComplete)

    ' Initialize IAutoComplete.
    IAutoComp.Init(handleEdit, iEnumList, registryPath, quickComplete)

    ' Set IAutoComplete Options.
    IAutoComp.SetOptions(Convert.ToUInt32(ShowOptions.AutoSuggest Or _
     ShowOptions.UpDownKeyDropsList Or ShowOptions.AutoAppend))

    ' Enable IAutoComplete.
    IAutoComp.Enable(True)

  End Sub   'New

  Public Sub Dispose() Implements System.IDisposable.Dispose

    Marshal.ReleaseComObject(IAutoComp)

  End Sub   'Dispose

  Public Property Enabled() As Boolean
    Get
      Return _enabled
    End Get
    Set(ByVal Value As Boolean)
      _enabled = Value
      If Value Then
        IAutoComp.SetOptions(Convert.ToUInt32(ShowOptions.AutoSuggest Or ShowOptions.UpDownKeyDropsList Or ShowOptions.AutoAppend))
      Else
        IAutoComp.SetOptions(Convert.ToUInt32(ShowOptions.None))
      End If
    End Set
  End Property   'Enabled

End Class

Look at the New constructor for the important arguments.

Bob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question