Posted by webmaster Guido on January 20, 2010
In Reply to Re: DbGrid/EditBox Search posted by Farhan Karimshah on
January 19, 2010
: what i mean is that there's a column that will contain the product ID/code and i want whatever i type in a Tedit box to automatically locate the row where that "CODE" is. To kinda jump to that row where the text in the ID/code column matches the Tedit box... thanx
Let's say that your Delphi table component is named Table1, and that it has a field named CODE. Furthermore you have a TEdit component named Edit1.
If the table is indexed on the field "CODE", you find the record where the field "CODE" is equal to the contents of Edit1 with the function FindKey, like this:
If there is no index on a field, you can use Locate, for example:
Table1.Locate('CODE', Edit1.Text, ); // corrected on 2010/01/22
In both cases, the DBGrid will be positioned at the desired row if the value is found, otherwise it
does not change its position.
If the value is found, the functions return True, otherwise it returns False.
Any problems? Don't hesitate to ask for more :)