Back to Devexpress

Incremental Search example

vcl-171183-expressquantumgrid-concepts-incremental-search-example.md

latest1.8 KB
Original Source

Incremental Search example

  • Jul 29, 2021

This example shows how incremental searching can be done programmatically. To allow searching, the View should not be in edit mode. Thus, the edit controller’s HideEdit method is used to close the currently active editor, if any. The search starts from the currently focused record. Thus, the sample below focuses the first record to start searching from it. The text to search is obtained from a TEdit control.

delphi
var
  AView: TcxCustomGridTableView;
//...
AView := TcxCustomGridTableView(Grid.FocusedView);
//Close an open editor if any
AView.Controller.EditingController.HideEdit(True);
//set focus to the first record
//to start the search from the beginning
AView.DataController.GotoFirst;
//start an incremental search within the tvFilmsCAPTION column
AView.DataController.Search.Locate(tvFilmsCAPTION.Index, Edit1.Text);
//...
//continue the search forward
AView.DataController.Search.LocateNext(True);
//...
//cancel the search
AView.DataController.Search.Cancel;
cpp
TcxCustomGridTableView * AView = (TcxCustomGridTableView*)Grid->FocusedView;
//Close an open editor if any
AView->Controller->EditingController->HideEdit(true);
//set focus to the first record
//to start the search from the beginning
AView->DataController->GotoFirst();
//start an incremental search
AView->DataController->Search->Locate(tvFilmsCAPTION->Index, Edit1->Text);
//...
//continue the search
AView->DataController->Search->LocateNext(true);
//...
//cancel the search
AView->DataController->Search->Cancel();