locked
combo box matching text RRS feed

  • Question

  • Hi All,

    Another combo box question!

    In VB6 datacombobox there was a property that you could set that filtered the item list as you typed in the combo box (extended matching I think it was called) so that as the user typed more characters in the box the filtering progressively narrowed down the number of items in the list.

    The .net control does not seem to have this facility, or does it?

    Do we have to programatically do it now?

     

    Cheers

     

    Andy

    Tuesday, November 29, 2011 3:14 PM

Answers

  • Andy,

    it works like it should. Try the sample below:


    'Visual Basic 2008 - .net 3.5 - Any CPU
    Public Class Form1
        Dim ComboBox1 As ComboBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ComboBox1 = New ComboBox
            ComboBox1.Location = New Point(40, 26)
            ComboBox1.Size = New Size(167, 21)
            Me.Controls.Add(ComboBox1)
            ComboBox1.Items.Add("X0003")
            ComboBox1.Items.Add("X0010")
            ComboBox1.Items.Add("X0011")
            ComboBox1.Items.Add("X0012")
            ComboBox1.Items.Add("P0001")
            ComboBox1.Items.Add("P0002")
            ComboBox1.Items.Add("P0003")
            ComboBox1.Items.Add("P0004")
            ComboBox1.Items.Add("P0005")
            ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest
            ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
        End Sub
    End Class
    
    

     


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Cor Ligthert Friday, December 2, 2011 7:46 AM
    • Marked as answer by AndyNakamura Monday, December 5, 2011 10:48 AM
    Friday, December 2, 2011 6:56 AM

All replies

  • Andy,

    the combobox has some properties to achieve this. E.g. Setting AutoCompleteMode to Suggest and AutoCompleteSource to ListItems could help you.

    Alwys a good start is reading the documentation: http://msdn.microsoft.com/en-us/library/t14e0ws8.aspx


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Cor Ligthert Friday, December 2, 2011 9:24 AM
    Tuesday, November 29, 2011 3:28 PM
  • Hi,

    It would seem the vb.net combobox doesn't have this function. (Or if it does I can't figure it out). Trawling the internet seems there are a number of solutions using the keypress etc events.
    The functionality I am lookig for is as

    X0001               If the user were to type X as the first character then all the P's would be excluded from the list
    X0002               then X001 would limit the list to X0010, X0011, X0012
    X0003
    X0010
    X0011
    X0012
    P0001
    P0002
    P0003

    The reason I need this is that the list could be very long. I'll modify one of the programatic solutions I found and post it here.

     

    Andy

    • Proposed as answer by Cor Ligthert Friday, December 2, 2011 7:46 AM
    • Unproposed as answer by Cor Ligthert Friday, December 2, 2011 9:24 AM
    Thursday, December 1, 2011 6:43 PM
  • Andy,

    it works like it should. Try the sample below:


    'Visual Basic 2008 - .net 3.5 - Any CPU
    Public Class Form1
        Dim ComboBox1 As ComboBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ComboBox1 = New ComboBox
            ComboBox1.Location = New Point(40, 26)
            ComboBox1.Size = New Size(167, 21)
            Me.Controls.Add(ComboBox1)
            ComboBox1.Items.Add("X0003")
            ComboBox1.Items.Add("X0010")
            ComboBox1.Items.Add("X0011")
            ComboBox1.Items.Add("X0012")
            ComboBox1.Items.Add("P0001")
            ComboBox1.Items.Add("P0002")
            ComboBox1.Items.Add("P0003")
            ComboBox1.Items.Add("P0004")
            ComboBox1.Items.Add("P0005")
            ComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest
            ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
        End Sub
    End Class
    
    

     


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Proposed as answer by Cor Ligthert Friday, December 2, 2011 7:46 AM
    • Marked as answer by AndyNakamura Monday, December 5, 2011 10:48 AM
    Friday, December 2, 2011 6:56 AM
  • Thanks Heslacher,

    Well, I tried eveyr combination possible with the auto complete properties to immitate the behavior of your routine but couldn't get it to work.

    The one you sent works perfectly!
    I placed the combobox with the form designer. The list items coming from a dataset. I must have had some property set incorrectly.
    I will investigate further.

    I'll try and figure out why it wasn't working correctly and mark as answered later if thats ok.

    Thanks

     

    Andy

    Friday, December 2, 2011 9:16 AM
  • Hi andyNakamura,

    Welcome to the MSDN forum.

    You can find the property by single click the combobox and it will lay in the right bottom of the VS form. If you can’t find it, please press “F4”, and you can find it. Here is a screen shot. Please set the property the same to me and have a try.

    If you have any additional questions, please feel free to let me know.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 2, 2011 9:54 AM
  • Thanks Mark,

    I found the properties ok, it's just that they didn't function like I expected.

    Maybe I did something strange populating the combobox or something

     

    Andy

    Friday, December 2, 2011 10:30 AM
  • I don't know what I was doing to make the strange behaviour but it works fine now.

     

    Thanks

    Monday, December 5, 2011 10:50 AM