Solved

ComboBox Autocomplete problem

Posted on 2010-11-29
8
1,350 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 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
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.

 

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 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