Solved

ComboBox Autocomplete problem

Posted on 2010-11-29
8
1,320 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…

911 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