Solved

ComboBox Autocomplete problem

Posted on 2010-11-29
8
1,306 Views
Last Modified: 2012-05-10
Hi. I have a problem with Combobox and AutoCompleteSource=ListItems problem.

For example in my database there is something like these:

Value  -  Name  - Option
------------------------------
1  - John Smith - X
2 - John Smith -  Y
3 - John Smith -  Z
------------------------------

But in ComboBox on typing "John" I can see and select only first John from database.
In case that i insert in database:

Value  -  Name  - Option
------------------------------
1  - John Smith - X
2 - John John -  Y
3 - John Joe -  Z
------------------------------

Now I can see and select all three of them.

How can I make ListItems to show everything from database, not just one if two records with same name exist?

It has to be ListItems, and DropDownStyle=DropDown, where user can type first few letters and listitem gives suggestions.


Thank You.
0
Comment
Question by:Grogel
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:barnesd1
ID: 34238801
I would suggest if you have 3 John Smiths the user wont know which one to choose anyway so add something that is unique like middle initial, employee id or location eg John Smith (200001), John Smith (201234), John Smith (230222)
0
 

Author Comment

by:Grogel
ID: 34242977
John Smith is just an example. Beside I do have few labes on he side of that combo with more details, but i need combobox to show all three of them.
0
 
LVL 27

Expert Comment

by:Ark
ID: 34306401
How do you fill combo? It seems that you have DISTINCT clause in your query, otherwise your combo should display ALL records
0
 

Author Comment

by:Grogel
ID: 34308316
I have simple bindingsource and tableadapter connected to database table, pretty much drag and drop. I will try to fill data manualy(through source code).
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 27

Expert Comment

by:Ark
ID: 34308399
Set AutoCompleteMode to SuggestAppend and see if all records shown in suggest dropdown tooltip
0
 

Author Comment

by:Grogel
ID: 34309396
Tried SuggestAppend, same thing. Can you tell me does this thing happens only for me? Is this working normally for you?
0
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 34317510
Sorry I misunderstood your question - you need duplicate records not in combo's dropdown list, but in suggestion list? Right? Unfortunately you can not do this (at least with a simple way - probably you can inherits from IAutoComplete interface but i'm not sure - seems Autocomlete uses SortedList which doesn't allow duplicates). Actually Autocomplite future was developed for EDIT controls to provide simple way for entering strings - instead of  typing whole string it suggests/appends it using few first chars. But it doesn't intended for choosing items. In your case it "helps" you to enter TEXT "John Smith" in an edit control of combo, not to choose appropriate item from combo. In your case you need another scenario:
1. Fill combo manually with items like Name_Option (like barnesd1 suggested)
2. Use custom Autocomplete collection
smth like this:
Dim acsc As New AutoCompleteStringCollection

Dim sName,sOption As String

For Each drv As DataRowView In yourBindingSource.List

'or For each r as DataRow In yourDataTable

   sName=drv("NameField")

   sOption = drv("OptionField")

  acsc.Add(sName & "_" & sOption"

Next



With ComboBox1

    .AutoCompleteMode = AutoCompleteMode.SuggestAppend

    .AutoCompleteSource = AutoCompleteSource.CustomSource

     .AutoCompleteCustomSource = acsc

End With





Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged

        Dim s As String = ComboBox1.Text

        If s.Contains("_") Then

            Dim sData() As String = s.Split("_"c)

            dim idx as integer=FindRecord(sData(0), sData(1)) ' your function to find appropriate item in your data

           yorBindingSource.Position=idx

        End If

    End Sub

Open in new window

0
 

Author Comment

by:Grogel
ID: 34317680
Thank you very much.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

759 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

21 Experts available now in Live!

Get 1:1 Help Now