Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ComboBox Autocomplete problem

Posted on 2010-11-29
8
Medium Priority
?
1,484 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
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

916 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