TAdvStringGrid
Example 89 : Using TAdvSearchEdit as inplace editor
Using the TAdvSearchEdit editor control as inplace editor for TAdvStringGrid is straighforward thanks to the component TAdvSearchEditEditLink. Via the TAdvSearchEditEditLink, the items for the list, the columns and the categories can be configured. In this example, we'll use the TAdvSearchEdit for simple filtered input to enter a country and a continent in the TAdvStringGrid. Therefore we need one column, no categories and the list of items will be loaded as a stringlist of words. We'll input the country in one column and the continent in another column. To get started, drop a TAdvStringGrid and two instances of a TAdvSearchEditEditLink on the form. Via the grid's OnGetEditorType event, we instruct the grid to use the first TAdvSearchEditEditLink for the country input and the second one for the continent input.
procedure TForm1.AdvStringGrid1GetEditorType(Sender: TObject; ACol, ARow: Integer; var AEditor: TEditorType); begin AEditor := edCustom; case ACol of 1: AdvStringGrid1.EditLink := AdvSearchEditEditLink1; 2: AdvStringGrid1.EditLink := AdvSearchEditEditLink2; end; end;
In the form constructor, we are configuring the TAdvSearchEditEditLink components. The countries are loaded from a text file in a TStringList and via this stringlist into the control. The TAdvSearchEditEditLink is setup to use one column. Default FilterConditions are used as column 0 will be used with a text match in the item's caption. In the countries TAdvSearchEditEditLink, color banding is enabled. We make use of the Items.LoadStrings() method to load the item data at once from the stringlist.
Setup of the first TAdvSearchEditEditLink:
var sl: TStringList; i: integer; begin AdvStringGrid1.Cells[1,0] := 'Country'; AdvStringGrid1.Cells[2,0] := 'Continent'; AdvSearchEditEditLink1.Columns.Clear; AdvSearchEditEditLink1.Columns.Add; AdvSearchEditEditLink1.CategoryButton.Visible := false; AdvSearchEditEditLink1.SearchButton.Visible := false; AdvSearchEditEditLink1.DropDownHeader.Caption := 'Countries'; AdvSearchEditEditLink1.DropDownSizable := true; AdvSearchEditEditLink1.Appearance.HighlightTextColor := clBlue; AdvSearchEditEditLink1.Appearance.Banding := true; sl := TStringList.Create; try sl.LoadFromFile('.\..\..\countries.txt'); // strip country for i := 0 to sl.Count - 1 do sl.Strings[i] := Copy(sl.Strings[i],4,Length(sl.Strings[i])); AdvSearchEditEditLink1.Items.LoadStrings(sl); finally sl.Free; end;
Setup of the second TAdvSearchEditEditLink:
AdvSearchEditEditLink2.Columns.Clear; AdvSearchEditEditLink2.Columns.Add; AdvSearchEditEditLink2.CategoryButton.Visible := false; AdvSearchEditEditLink2.SearchButton.Visible := false; AdvSearchEditEditLink2.DropDownHeader.Caption := 'Countries'; AdvSearchEditEditLink2.DropDownSizable := true; AdvSearchEditEditLink2.Appearance.HighlightTextColor := clGreen; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'Europe'; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'North-America'; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'South-America'; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'Africa'; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'Australia'; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'Asia'; AdvSearchEditEditLink2.Items.Add.Captions[0] := 'Antartica';
With a more elaborate setup, complex inplace search edit as below are possible:
×