Hi Everyone, I have a combobox that i need to populate with a datasource from my database. Because i want to make this autocomplete AND have the possibility to enter new things, i have done the following:
Private void LoadAuthors()
{
cmbAuthors.DataSource = Dataset;
cmbAuthors.DisplayMember = "Name";
cmbAuthors.ValueMember = "Id";
cmdAuthors.AutoCompleteCustomSource = AutoCompleteStringCollectionIMadeFromTheDataSet;
cmbAuthors.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cmbAuthors.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
And all is well in Autocomplete land and datasource land.. however... to find out if they entered a new name ( and i need to pop up a form to complete extra info), i have a handler for the "leave" event on the combobox:
private void cmbAuthors_Leave(object sender, EventArgs e)
{
if (cmbAuthors.SelectedValue != null)
{
MessageBox.Show("We know the dude...");
}
else
{
MessageBox.Show("Who's that ? better make a new one !");
// FrmAuthorDetails FrmAddNewAuthor = new FrmAuthorDetails();
}
}
now the problem is: When you leave the combobox, the selectedvalue always is null, i get the "who's that" message, and when i click ok to that THEN the selectedindex event fires on the combobox (and thus only getting the required data to make this check) Is there any way to make sure the selectedindex event is fired first or manually fire the autocomplete so it will complete BEFORE, it actually fires the leave event ? Any other intelligent solution i could not think of or have not found on google codeproject is welcome too obviously ;-)
Do Or Don't, there is no "try catch ex as exception end try"