Results 1 to 15 of 15

Thread: Combobox autocomplete

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Combobox autocomplete

    I'm trying to finish off this project that someone else started - terrible design.

    anyway, there is a combobox with a list of items. It does implement the SelectedIndexChanged event, which when the index is changed, binds data toa datasource to be seen to the user. Thats fine.

    problem is, if we have say:

    alpha
    november
    tango
    tangle


    if we type in "t", it will go to "tango" - thats fine. But if we continue to type in "ta", it will go to "tango", bind the data, then go to "alpha" and bind the data, so basically it is not drill down to the right item that we want, in this case "tango"

    anyone have any ideas how to make it so that when the user types in say, 2-3 letters, it will drill down to that item without it going to the other items in the list when we type in the second character etc... ?

    Obviously, its fine when we have no databinding going on the selectedindexchanged event. I do know whats going on but dont know how to implement the solution or where to go from here.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Combobox autocomplete

    Can we see this SelectedIndexChanged event handler?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    sure but really there is nothing to see

    Code:
    orderBindingSource.EndEdit();
                
    
                Order o = orderBindingSource.Current as Order;
    
                TList<Product> productList = productService.GetByCustomerID(o.CustomerID);
    
                productBindingSource.DataSource = productService.GetByCustomerID(o.CustomerID);
    
                foreach (OrderDetail orderDetail in o.OrderDetailCollection)
                {
                    if ( productList.Count > 0 )
                    {
                        if ( productList.Find(ProductColumn.ID,orderDetail.ProductID) == null )
                        {
                            orderDetail.ProductID = productList[0].ID;
                        }
                    }
                    else
                    {
                        orderDetail.ProductID = 0;
                    }
                }

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Combobox autocomplete

    What's the DropDownStyle of this control: DropDown or DropDownList? Also, what are it's auto-complete properties set to?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    It's DropDown and the auto-complete is None.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Combobox autocomplete

    That makes no sense to me. How can typing into the ComboBox change the SelectedIndex anyway? There must be something in another event handler, like TextChanged or KeyPress, that is causing the issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    none at all, thats the only event that is implemented in the code for that control.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Combobox autocomplete

    I don't really see how that's possible. I just created a new WinForms app and added a ComboBox to the form. I then changed the form's code file to this:
    C# Code:
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Text;
    7. using System.Windows.Forms;
    8.  
    9. namespace WindowsApplication1
    10. {
    11.     public partial class Form1 : Form
    12.     {
    13.         public Form1()
    14.         {
    15.             InitializeComponent();
    16.         }
    17.  
    18.         private void Form1_Load(object sender, EventArgs e)
    19.         {
    20.             List<Order> orders = new List<Order>();
    21.  
    22.             orders.Add(new Order(1, "alpha"));
    23.             orders.Add(new Order(2, "november"));
    24.             orders.Add(new Order(3, "tango"));
    25.             orders.Add(new Order(4, "tangle"));
    26.  
    27.             this.bindingSource1.DataSource = orders;
    28.             this.comboBox1.DataSource = this.bindingSource1;
    29.         }
    30.  
    31.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    32.         {
    33.             Console.WriteLine((this.bindingSource1.Current as Order).Name);
    34.         }
    35.     }
    36.  
    37.     public class Order
    38.     {
    39.         private int _id;
    40.         private string _name;
    41.  
    42.         public int ID
    43.         {
    44.             get { return _id; }
    45.             set { _id = value; }
    46.         }
    47.  
    48.         public string Name
    49.         {
    50.             get { return _name; }
    51.             set { _name = value; }
    52.         }
    53.  
    54.         public Order(int id, string name)
    55.         {
    56.             this._id = id;
    57.             this._name = name;
    58.         }
    59.     }
    60. }
    When I ran the project the Output window showed "alpha" as expected as the first item was selected. I then typed "t" and "a" and, as expected, there was no new output because entering characters into the box doesn't raise the SelectedIndexChanged event.

    I suggest that you place a breakpoint on the first line of the event handler and then when it's hit take a look at the Call Stack window to see where it has come from. I just don't see how it could be caused merely by entering a letter in the box.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    i agree with you, i can do it fine in a new project (typing in letters and it filters down to the item in the dropdownlist)

    ill see what i can find and post back

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  10. #10
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    Re: Combobox autocomplete

    Umm, maybe I am retarded, but shouldn't you have to click a Button to begin any database stuff?

    if you had

    tab
    tabb
    taabbitha

    in a drop down the last thing you want is for the thing to start doing stuff when you havent made sure that is the item you want.

    In other words, have them select the item then click a button to start all the work.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Combobox autocomplete

    Maybe it would be worth deleting this ComboBox and adding a new one. Something screwy is going on so that should hopefully get rid of that, then you can wire up the new one as you want.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    its just a project ive taken over and cant really change the "specs" of it. The designer is also screwed up so I'll give it a shot in terms of removing and re-adding the combobox programmatically in code behind/designer code.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Combobox autocomplete

    I feel your pain. Good luck.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    ok I tried re-doing the combobox but it made no difference (and I did not implement the SelectedIndexChanged event yet).

    It still seems to think that everytime I press a letter (together in a sequence when typing a word) that each letter is the first input it ever recieved.

    any further suggestions?

    I tried this on a new project, just a simple project and binding the combobox to a datasource and it acted in the same way! it wont let you type to filter down to the name you want...but only accepts the first character as input and thats it.
    Last edited by Techno; Aug 20th, 2007 at 08:57 AM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Combobox autocomplete

    hang on, i think i got it!

    of course, i remember now - its coming back to me. its been a year since i did this.

    Set the AutoCompleteMode to "Suggust" and the AutoCompleteSource to "ListItems" for the combobox.....and it did it

    unfortunately the selectedindexchanged event will fire when it is "autocompleting" which means im back to square one. So I guess maybe I need to add a button instead to load the record which is a downfall
    Last edited by Techno; Aug 20th, 2007 at 09:11 AM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width