Solved

multi column combobox auto complete

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Shortcut (VB) 4 46
Regex validation 2 25
Creating a route in asp.net webforms 2 30
How do sunrise and sunset times change with altitude 14 31
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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