|
-
Aug 17th, 2007, 05:58 PM
#1
Thread Starter
PowerPoster
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.
-
Aug 17th, 2007, 08:37 PM
#2
Re: Combobox autocomplete
Can we see this SelectedIndexChanged event handler?
-
Aug 18th, 2007, 07:03 AM
#3
Thread Starter
PowerPoster
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;
}
}
-
Aug 18th, 2007, 07:16 AM
#4
Re: Combobox autocomplete
What's the DropDownStyle of this control: DropDown or DropDownList? Also, what are it's auto-complete properties set to?
-
Aug 18th, 2007, 07:30 AM
#5
Thread Starter
PowerPoster
Re: Combobox autocomplete
It's DropDown and the auto-complete is None.
-
Aug 18th, 2007, 07:33 AM
#6
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.
-
Aug 18th, 2007, 07:52 AM
#7
Thread Starter
PowerPoster
Re: Combobox autocomplete
none at all, thats the only event that is implemented in the code for that control.
-
Aug 18th, 2007, 09:19 AM
#8
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:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
List<Order> orders = new List<Order>();
orders.Add(new Order(1, "alpha"));
orders.Add(new Order(2, "november"));
orders.Add(new Order(3, "tango"));
orders.Add(new Order(4, "tangle"));
this.bindingSource1.DataSource = orders;
this.comboBox1.DataSource = this.bindingSource1;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine((this.bindingSource1.Current as Order).Name);
}
}
public class Order
{
private int _id;
private string _name;
public int ID
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public Order(int id, string name)
{
this._id = id;
this._name = name;
}
}
}
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.
-
Aug 18th, 2007, 10:05 AM
#9
Thread Starter
PowerPoster
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
-
Aug 18th, 2007, 07:10 PM
#10
PowerPoster
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.

-
Aug 18th, 2007, 08:21 PM
#11
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.
-
Aug 19th, 2007, 12:35 AM
#12
Thread Starter
PowerPoster
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.
-
Aug 19th, 2007, 12:46 AM
#13
Re: Combobox autocomplete
I feel your pain. Good luck.
-
Aug 20th, 2007, 08:45 AM
#14
Thread Starter
PowerPoster
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.
-
Aug 20th, 2007, 09:01 AM
#15
Thread Starter
PowerPoster
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|