Code Comments
Programming Forum and web based access to our favorite programming groups.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!
Post Follow-up to this messageIs that you fill the combobox with a datasouce or fill it by adding item to its item collection?
Post Follow-up to this messageDid you find a solution for this? I would be very interested in hearing it if you did! Thanks, Kevin
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.