ComboBox AutoComplete with id value
-
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"
-
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"
-
what about trying to replace
if (cmbAuthors.SelectedValue != null)
with
if(cmbAuthors.Items.Contains(cmbAuthors.Text))//check if name is in the list
Life goes very fast. Tomorrow, today is already yesterday.
Hmm.. unfortunately, it does not even recognize that :( Strange thing is, if i look at what cmbAuthors.text contains, it is the text i want.. but it does not work. so that got me thinking and i tryed:
cmbAuthors.selectedtext = cmbauthors.text;
But.. helas.. it only uses the actual typed text so for example "mad" if you are looking for madonna :s I am thinking that autocomplete uses the same event (leave) to do it's autocomplete magic.. When i change the handler to the "onSelectedValueChanged", it does work .. however, that event get's fired multiple times on Runtime (so when binding the datasource for example)... and does not fire when the value you type in is unknown in the dataset/autocomplete The problem is that i really have to do the check when leaving the combo ...
Do Or Don't, there is no "try catch ex as exception end try"
-
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"
For the people that want to know. Apparently the Leave event is fired before autocomplete can do it's magic however, Putting the handler on the LostFocus event solves the issue. It's just not visibile in the VS2005 UI... Solved ;-)
Do Or Don't, there is no "try catch ex as exception end try"