ArunVashist
asked on
Visual C#, Autosuggest Combobox
Hi Friends,
I am developing a windows application using VS 2008 with C#, I need a combobox with autosuggest feature e.g. when user enter any key in combobox using that text application fetches related records from database and show as items in combobox and user could select from the given items.
say user enters "com" and application query a specific database to fetch records starting with "Com%" and user could select from it.
thanks,
I am developing a windows application using VS 2008 with C#, I need a combobox with autosuggest feature e.g. when user enter any key in combobox using that text application fetches related records from database and show as items in combobox and user could select from the given items.
say user enters "com" and application query a specific database to fetch records starting with "Com%" and user could select from it.
thanks,
hi ArunVashist,
For Visual C#, Autosuggest Combobox follow these below links.
http://www.codeproject.com/KB/cpp/AutoCompleteComboBox.aspx
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/autocompleteclientside/defaultcs.aspx
http://www.freevbcode.com/ShowCode.asp?ID=7007
http://www.telerik.com/community/forums/aspnet-ajax/combobox/auto-complete-combo-box-prefix-length.aspx
For Visual C#, Autosuggest Combobox follow these below links.
http://www.codeproject.com/KB/cpp/AutoCompleteComboBox.aspx
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/autocompleteclientside/defaultcs.aspx
http://www.freevbcode.com/ShowCode.asp?ID=7007
http://www.telerik.com/community/forums/aspnet-ajax/combobox/auto-complete-combo-box-prefix-length.aspx
ASKER
Hi Cute Bug,
As suggested I am using following code in "onTextChanged" event of combox box but I am getting the error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
following is the code.
private void cbMedicineName_TextChanged (object sender, EventArgs e)
{
string QText;
if (cbMedicineName.Text == "" || cbMedicineName.Text.Length < 2)
{
QText = "Do not load";
}
else
{
QText = cbMedicineName.Text;
}
OleDbDataReader Drugs = objPatient.GetDrugsList(QT ext);
DataSet temp = new DataSet();
temp.Load(Drugs, LoadOption.OverwriteChange s, "DrugsList");
cbMedicineName.AutoComplet eMode = AutoCompleteMode.Suggest;
cbMedicineName.AutoComplet eSource = AutoCompleteSource.CustomS ource;
cbMedicineName.AutoComplet eCustomSou rce.Clear( );
foreach (DataRow dr in temp.Tables["DrugsList"].R ows)
{
cbMedicineName.AutoComplet eCustomSou rce.Add(dr ["DrugName "].ToStrin g());
}
}
As suggested I am using following code in "onTextChanged" event of combox box but I am getting the error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
following is the code.
private void cbMedicineName_TextChanged
{
string QText;
if (cbMedicineName.Text == "" || cbMedicineName.Text.Length
{
QText = "Do not load";
}
else
{
QText = cbMedicineName.Text;
}
OleDbDataReader Drugs = objPatient.GetDrugsList(QT
DataSet temp = new DataSet();
temp.Load(Drugs, LoadOption.OverwriteChange
cbMedicineName.AutoComplet
cbMedicineName.AutoComplet
cbMedicineName.AutoComplet
foreach (DataRow dr in temp.Tables["DrugsList"].R
{
cbMedicineName.AutoComplet
}
}
ASKER
HI Tapan,
I need a combobox with autosuggest feature which updated the items in combobox from database according to text input. The examples you sent are for autocomplete which just search the existing items in combobox.
Thanks,
I need a combobox with autosuggest feature which updated the items in combobox from database according to text input. The examples you sent are for autocomplete which just search the existing items in combobox.
Thanks,
You can do it this way
AutoCompleteStringCollection acsc = new AutoCompleteStringCollection();
foreach (DataRow dr in temp.Tables["DrugsList"].Rows)
{
acsc.Add(dr["DrugName"].ToString());
}
cbMedicineName.AutoCompleteCustomSource = acsc;
cbMedicineName.AutoCompleteMode = AutoCompleteMode.Suggest;
cbMedicineName.AutoCompleteSource = AutoCompleteSource.CustomSource;
ASKER
Hi Cute bug,
Actually the suggested method works for the first time but when on "KeyPress" or "TextChanged" event I requery the database and try to refresh items of AutoCompleteSoure.CustomSo urce I get the error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
it would be better if you send me some working sample code.
thanks,
Actually the suggested method works for the first time but when on "KeyPress" or "TextChanged" event I requery the database and try to refresh items of AutoCompleteSoure.CustomSo
it would be better if you send me some working sample code.
thanks,
I think you do not have to requery in the database each time you do a key press.
Instead during the creation of the combobox, set the autocompletecustom source like the code given previously.
AutoComplete will handle the rest when you do a keypress...
Instead during the creation of the combobox, set the autocompletecustom source like the code given previously.
AutoComplete will handle the rest when you do a keypress...
ASKER
Hi Cute Bug,
Actually the item count is more then 200k, and it take hell lot of time loading these values into list, so I want only to add required items in combobox. so requery and rebinding become necessary, kindly guide if any other way out is there.
thanks,
Actually the item count is more then 200k, and it take hell lot of time loading these values into list, so I want only to add required items in combobox. so requery and rebinding become necessary, kindly guide if any other way out is there.
thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And set the AutoCompleteCustomSource property as detailed in the following link
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/d7672f50-a620-4b5c-acc8-7ce7c61b04e9