AutoComplete ComboBox with DroppedDown=true
- From: "aferriere" <aferriere@xxxxxxxxx>
- Date: 12 Jan 2007 08:29:12 -0800
Hi
I have create an autocomplete combobox in VS.NET 1.1 based on some
articles I found on the net. Every thing works fine except when you
turn on DroppedDown=true to make the combo behave like an IE
autocomplete combobox. The combox seems to be working fine but when you
try to get combobox.Text or combobox.SelectedIndex through code they
point to the previous selection instead of showing the value currently
selected. Any one figure out how to get around this issue ????
Below is the code. If you comment the line DroppedDown=true; everything
should work fine. But if you leave it there you can reproduce the above
problem.
public class ACComboBox : System.Windows.Forms.ComboBox
{
public ACComboBox():base()
{
}
protected override void
OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
DroppedDown=true;
if (char.IsControl(e.KeyChar))
return;
string ToFind = Text.Substring(0,SelectionStart) + e.KeyChar;
int Index = FindStringExact(ToFind);
if (Index == -1)
Index = FindString(ToFind);
if (Index == -1)
return;
SelectedIndex = Index;
SelectionStart = ToFind.Length;
SelectionLength = Text.Length - SelectionStart;
e.Handled = true;
base.OnKeyPress(e);
}
protected override void OnLeave(System.EventArgs e)
{
string text=Text;
int index=FindStringExact(text,-1);
if(index<0)
index=0;
SelectedIndex = index;
base.OnLeave(e);
}
}
.
- Follow-Ups:
- Re: AutoComplete ComboBox with DroppedDown=true
- From: Bryan Phillips
- Re: AutoComplete ComboBox with DroppedDown=true
- Prev by Date: Component, Properties window and Object Collection Editor
- Next by Date: UserControl and TextChanged event
- Previous by thread: Component, Properties window and Object Collection Editor
- Next by thread: Re: AutoComplete ComboBox with DroppedDown=true
- Index(es):
Relevant Pages
|