Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search key words

Status
Not open for further replies.

room24

Programmer
Dec 28, 2003
83
JM
in delphi help under the index tab there are two fields labelled 1 and 2 the one labelled 1 looks like an edit box to me and the one labelled 2 looks like a ListBox i need to code a search like that but can anyone explain to me the concept of programming this feature..
 
Just like you said, add a TEdit and a TListBox to a form and populate the TListBox either programmatically or in design mode.

Then write code in the TEdit.OnChange event that evaluates its current Text property value and either searches or filters the Strings in the TListBox.

If you want it to work EXACTLY like the index option in the Windows help, you would also add code to the TListBox.OnClick event to replace the TEdit.Text value with the current selection in the TListBox.

This should get you started.
 
ok cool, but where do i write the code populate the TListBox with these strings and how would i filter or search these strings in my TListBox
 
Where are the strings coming from? If they're in a file, you would use Listbox1.Items.LoadFromFile('FileName'). If they're set in the code you use .Add('item') for each instead of load from file.

To search, if you're searching for a complete entry, you'd use Listbox1.Items.IndexOf('string'). If you're searching for part of a string, you'd have to walk through the Items stringlist looking for the first string that meets the criteria.

-Dell
 
To answer the question of where you write the code to populate the TListbox (using Hilfy's suggestions on how to do it) I would recommend adding it to the form's OnCreate event.
 
suppose i wanted to use a dbgrid instead of the TListbox how would i impliment that
 
also the dbgrid has more than one column and i want to search a specific column locating a specific row
 
If you want to use a DBgrid, you'll need a database table to connect to through some sort of TDataSet descendant (TTable, TQuery, TADOTable, TADOQuery, etc.) At that point, you can use the Locate method of the dataset to locate the record that matches your criteria.

-Dell
 
is possible to give me an example say i have a

1. dbgrid = dbgrid
2. TEdit = string
3. dataste = dsSelector
4. query = quSelector

these columns are on the grid id | name | address

i want whenever all or part of a name is entered in string the grid focuses to the first name containing all or part of string
 
Code:
quSelector.Locate('NAME', Edit1.Text, [loCaseInsensitive, loPartialKey]);

If you have more than one field that you're using to locate a record, it will look like this:
Code:
quSelector.Locate('NAME;ADDRESS', VarArrayOf(Edit1.Text, Edit2.Text), [loCaseInsensitive, loPartialKey]);
Take out "loCaseInsensitive" if you want a case sensitive search.

-Dell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top