Re: Searching in a listbox

Posted by webmaster Guido on November 27, 2001 at 18:47:18:

In Reply to: Webmaster Guido, question about an old post of yours posted by Michael Ross

: In the post article you provide a way to search a listbox incrementally.
: Your code works great!

: My question is: Where, in that code, could I place a MessaeDlg informing if "No Matches Found"?

: Have already preceded the code with:

If Edit1.text = '' then begin //check to make sure text has been entered
  MessageBeep(MB_ICONEXCLAMATION);
  MessageDlg('Please enter the text you wish to search for', mtError, [mbOK], 0);
  Edit1.SetFocus; //set focus if no text entered.
  Exit; //quit subroutine if the edit box is empty
end

: But am having no luck figuring where to put the "No Matches Found" message.

-------

You can change the last line of the routine:

if Found then LB.ItemIndex := i;

to the following:

if Found then LB.ItemIndex := i
else MessageDlg('No match found', mtWarning, [mbOk], 0);

For those of you who want to follow along, you can open a new window with the original message and code by clicking here:
Message 512


[ DelphiLand FAQ ]

Related articles:

ListBox, find string
ListBox, modify