Solved

ComboBox Autocomplete problem

Posted on 2010-11-29
8
1,414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 28

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
LVL 28

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 28

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

626 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