Solved

multi column combobox auto complete

Posted on 2006-07-05
3
553 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now