Jep habs bemerkt..
Funktioniert bestens.
Habe es mit databinding gelöst und anschliessend den Validating Event verwendet..
private void cboCountry_Validating(object sender, CancelEventArgs e)
{
if(((ComboBox)sender).Text.Length > 0)
{
string text = ((ComboBox)sender).Text.ToUpper();
bool valueFound = false;
for(int i = 0; i < ((ComboBox)sender).Items.Count; i++)
{
if(((ComboBox)sender).Items[i].ToString().CompareTo(text) == 0)
{
valueFound = true;
break;
}
}
if(!valueFound)
{
e.Cancel = true;
}
}
}
private void dbReadCountries()
{
try
{
this.countryArrayList.Clear();
IDbCommand oraCmd = OracleDBManager.Instance.CreateDbCommand();
oraCmd.CommandText = "SELECT * FROM COUNTRIES ORDER BY COUNTRY";
using (IDataReader or = OracleDBManager.Instance.ExecuteReader(null, oraCmd))
{
while (or.Read())
{
this.countryArrayList.Add(new CountryItem(or["COUNTRY"].ToString(), or[" code"].ToString()));
}
}
// binding DataSource to Combobox
this.cboCountry.DataSource = null;
this.cboCountry.DisplayMember = "Text";
this.cboCountry.ValueMember = "Name";
this.cboCountry.DataSource = countryArrayList;
string[] autoCompletion = new string[countryArrayList.Count];
for(int i = 0; i < countryArrayList.Count; i++)
{
autoCompletion[i] = this.cboCountry.Items[i].ToString();
}
this.cboCountry.AutoCompleteCustomSource = new AutoCompleteStringCollection();
this.cboCountry.AutoCompleteCustomSource.AddRange(autoCompletion);
}
catch (System.Exception ex)
{
}
}