Search as you type

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Is there any known implementation of search as you type (in a db) in c#. Say
for argument sake, as I type in the 1st name the number of names in my
combobox decrease.
 
Dave said:
Is there any known implementation of search as you type (in a db) in c#.
Say
for argument sake, as I type in the 1st name the number of names in my
combobox decrease.

You need to implement this yourself. It's not difficult

SELECT * FROM People WHERE FirstName LIKE abc%

Michael
 
Dave said:
What event I would need to attach this code to?

The change event for the textbox. Where are you getting the list of names
from? I was assuming a database which might not be correct.

Michael
 
Peter Bromberg said:
KeyUp of the TextBox would be a good candidate.

That's not really a good way to do it because they could change the text in
the textbox without using the keyboard. Changed event is probably better.

Michael
 
Chris Shepherd said:
Isn't there a way to bind to a Data Source for autocompletion?

Chris.

Yes, there is. It is outlined brilliantly in Brian Noyes' DataBinding book.
Let me know if you want more info, and I'll dig it up and post the code
example. (Awesome book, by the way, worth the $ for the datagridview stuff
alone.)

RobinS.
GoldMail, Inc.
 
Yes, there is. It is outlined brilliantly in Brian Noyes' DataBinding
book. Let me know if you want more info, and I'll dig it up and post the
code example. (Awesome book, by the way, worth the $ for the datagridview
stuff alone.)

RobinS,

can you post sample ?
I'm very interested about it.
I have tried to use AutoComple in Virtual DataGridView without success.
Mostly Autocomplete menu does not appear. Sometimes it appers, no idea which
controls this.

I'm interested on using DataGridView Virtual mode. Does this book cover
virtual mode or only as its title says, Databindig ?

Andrus.
 
Andrus said:
RobinS,

can you post sample ?
I'm very interested about it.
I have tried to use AutoComple in Virtual DataGridView without success.
Mostly Autocomplete menu does not appear. Sometimes it appers, no idea
which controls this.

I'm interested on using DataGridView Virtual mode. Does this book cover
virtual mode or only as its title says, Databindig ?

Andrus.

Yes, the book does cover using the DGV in virtual mode. I will post either
the code for the AutoComplete (I'm using it for one of my comboboxes), or a
link where you can find it, this weekend.

RobinS.
 
Yes, the book does cover using the DGV in virtual mode. I will post either
the code for the AutoComplete (I'm using it for one of my comboboxes), or
a link where you can find it, this weekend.

RobinS,

thank you.
Will this code allow to use AutoComplete in a Combobox placed in Virtual
Mode DataGridview ?
Will autocomplete work OK overv low speed internet ?

Andrus.
 
I don't know why not. Using AutoComplete involves keeping a local copy of
the table. I'll post it this weekend.

RobinS.
GoldMail, Inc.
-----------
 
Here's the example of auto-complete. This example is for a combobox that
holds a list of fonts available. So I have the data table that is bound to
the combobox for the user's selection, and a collection of entries for the
auto-completion. I would think this would work for a textbox; if it doesn't,
post back and I'll go pull out Brian's book. I'm sure he has an example for
a textbox.

-------------------------------------

//variable checked in the selectedIndexChanged event
// to suppress the event when the combobox
// is being loaded
private bool m_loading;

//table of fonts
private DataTable dtFonts;

//collection to use for auto-completion of the font names
private AutoCompleteStringCollection m_Fonts;

private void LoadFontComboBox()
{
m_Loading = true;
//Set up datatable to bind to the combobox
// so you can use autocomplete.
dtFonts = new DataTable();
dtFonts.Columns.Add(new DataColumn("fontName"));

m_Fonts = new AutoCompleteStringCollection();
InstalledFontCollection m_allFonts = new InstalledFontCollection();
foreach (FontFamily oneFamily in m_allFonts.Families)
{
if (oneFamily.IsStyleAvailable(FontStyle.Regular))
{
dtFonts.Rows.Add(oneFamily.Name);
m_Fonts.Add(oneFamily.Name);
}
}
FontFamilyComboBox.AutoCompleteCustomSource = m_Fonts;
FontFamilyComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
FontFamilyComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource;

//databind the combobox
FontFamilyComboBox.DataSource = dtFonts;
FontFamilyComboBox.DisplayMember = "fontName";
FontFamilyComboBox.ValueMember = "fontName";

m_Loading = false;
}
 
Here's the example of auto-complete.

Thank you.
I have the following requirements:

1. Combobox dropdown list must display more than one column, e.q product
code and product name.
2. Combobox dropdown list must be virtual (like DataGridView in virtual
mode).
(I have lookup table which can contain up to 500000 rows. So I think that it
is reasonable to show only records which are currently visible in screen).

Any sode sample which implements this? How to create
DrataGridview in virtual mode when user opens dropdown list ? Is it
reasonable to create form containing grid from Combobox dropdown event ?

DaisyCombo for .NET from http://www.springsys.com seems to implement
requirement (1)

Andrus.
 
Andrus said:
Thank you.
I have the following requirements:

1. Combobox dropdown list must display more than one column, e.q product
code and product name.
2. Combobox dropdown list must be virtual (like DataGridView in virtual
mode).
(I have lookup table which can contain up to 500000 rows. So I think that
it
is reasonable to show only records which are currently visible in screen).

Any sode sample which implements this? How to create
DrataGridview in virtual mode when user opens dropdown list ? Is it
reasonable to create form containing grid from Combobox dropdown event ?

DaisyCombo for .NET from http://www.springsys.com seems to implement
requirement (1)

Andrus.

I don't know offhand of a way to do this. Maybe you should just buy Brian's
book and see if it helps. I haven't worked with virtual grids, I just know
he has a decent chapter on it.

As for the combobox problem, I would probably implement some kind of search
button rather than using a dropdown box.

Good luck.
RobinS.
 
FontFamilyComboBox.AutoCompleteCustomSource = m_Fonts;
FontFamilyComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
FontFamilyComboBox.AutoCompleteSource =
AutoCompleteSource.CustomSource;

Why you do'nt use List as AutoCompleteSource ?
Why you are messing with custom source ?
Using List This makes code simpler.

Andrus.
 
Andrus said:
Why you do'nt use List as AutoCompleteSource ?
Why you are messing with custom source ?
Using List This makes code simpler.

Andrus.

I wanted to provide the list of values for the auto-complete myself, so I
have to set AutoCompleteSource to CustomSource, and provide the
AutoCompleteStringCollection (m_Fonts) to use as the source.

Setting the AutoCompleteMode to SuggestAppend means that as the users type,
the dropdown list will display matches and append any missing letters for
the selected item when the user tabs out of the control.

This is from an example in Brian Noyes' Data Binding book, and it works
beautifully for me. As far as I know (I haven't tried it), you have to bind
to an AutoCompleteStringCollection to get it to work, not a List<T>.

RobinS.
GoldMail, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top