[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

multi column combobox auto complete

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
foobarr
Asked:
foobarr
2 Solutions
 
carmodykCommented:
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
 
foobarrAuthor Commented:
no this is not what i was looking for thanks though!
0
 
Bob LearnedCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now