Re: AutoComplete ComboBox with DroppedDown=true
- From: "Bryan Phillips" <bphillips@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 15 Jan 2007 11:14:37 +0000
I was unable to reproduce the problem using a simple form with your ACComboBox and a button. Can you post a little more code so I can continue looking at the problem?
Thanks,
--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
"aferriere" <aferriere@xxxxxxxxx> wrote in message news:1168619352.635674.32310@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
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: aferriere
- Re: AutoComplete ComboBox with DroppedDown=true
- References:
- AutoComplete ComboBox with DroppedDown=true
- From: aferriere
- AutoComplete ComboBox with DroppedDown=true
- Prev by Date: Re: VS Deleting user control designer code
- Next by Date: Re: System.Windows.Forms.DateTimePicker
- Previous by thread: AutoComplete ComboBox with DroppedDown=true
- Next by thread: Re: AutoComplete ComboBox with DroppedDown=true
- Index(es):