Home > Archive > C# > January 2005 > Autocomplete combobox selectedvalue returns undefined value
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Autocomplete combobox selectedvalue returns undefined value
|
|
| Brotto 2004-12-10, 3:58 pm |
| Hi all,
I am pulling my hair out here.
I am trying to implement a dropdown (databound - valuemember and
displaymember) which drops down and has an auto complete. The code
below appears to work okay but when I try and save the value away
using the SelectedValue property it returns "undefined value".
Here is my code:
private void cboPBrokerB_KeyPress(object sender,
system.Windows.Forms.KeyPressEventArgs e)
{
AutoCompleteCombo_KeyPress(((ComboBox)se
nder),e);
}
private void AutoCompleteCombo_KeyPress(ComboBox cbo,
System.Windows.Forms.KeyPressEventArgs e)
{
if ((cbo.DropDownStyle ==
ComboBoxStyle.DropDown)&&(cbo.DroppedDown==false))
cbo.DroppedDown = true;
if (char.IsControl(e.KeyChar))
return;
string ToFind = cbo.Text.Substring(0, cbo.SelectionStart) +
e.KeyChar;
int Index = cbo.FindStringExact(ToFind);
if (Index == -1)
Index = cbo.FindString(ToFind);
if (Index == -1)
{
e.Handled = true;
return;
}
cbo.SelectedIndex = Index;
cbo.SelectionStart = ToFind.Length;
cbo.SelectionLength = cbo.Text.Length - cbo.SelectionStart;
e.Handled = true;
}
Any assistance would be greatly appreciated!
Thanks in advance - Brett!
| |
|
| Is that you fill the combobox with a datasouce or fill it by adding item to its item collection? | |
|
| Did you find a solution for this? I would be very interested in hearing it if you did!
Thanks,
Kevin |
|
|
|
|