Frequently Asked Component Specific Questions
Options |
Display all FAQ items |
Displaying items 1 to 1 of 1, page 1 of 1
<< previous next >>
TAdvStringGrid
Associating a unique ID with search list items for TAdvSearchEdit used in TAdvStringGrid
Associating a unique ID with search list items for TAdvSearchEdit used in TAdvStringGrid
When a TAdvSearchEdit is used as inplace editor in the grid via TAdvSearchEditEditLink, it is often desirable to have associated an unique ID with each item in the searchedit and retrieve this ID upon selection.
The following code demonstrates this for a TAdvSearchEdit used as inplace editor where the unique ID is set via the SearchListItem.Tag property and retrieved when editing ends in the grid.OnCellValidate event:
procedure TForm1.FormCreate(Sender: TObject); var si: TSearchListItem; begin // initialize the search edit AdvSearchEditEditLink1.Columns.Add; AdvSearchEditEditLink1.CategoryButton.Visible := false; AdvSearchEditEditLink1.SearchButton.Visible := false; // tag holds the unique value si := AdvSearchEditEditLink1.Items.Add; si.Captions[0] := ''BMW''; si.Tag := 1; si := AdvSearchEditEditLink1.Items.Add; si.Captions[0] := ''Mercedes''; si.Tag := 2; si := AdvSearchEditEditLink1.Items.Add; si.Captions[0] := ''Audi''; si.Tag := 3; end; // use the OnGetEditorType event to specify the TAdvSearchEditEditLink as inplace editor: procedure TForm1.AdvStringGrid1GetEditorType(Sender: TObject; ACol, ARow: Integer; var AEditor: TEditorType); begin AEditor := edCustom; AdvStringGrid1.EditLink := AdvSearchEditEditLink1; end; // retrieve the unique ID of the selected item in the OnCellValidate event: procedure TForm1.AdvStringGrid1CellValidate(Sender: TObject; ACol, ARow: Integer; var Value: string; var Valid: Boolean); var index,t: integer; begin index := (AdvSearchEditEditLink1.GetEditControl as TAdvSearchEdit).SearchList.ItemIndex; t := (AdvSearchEditEditLink1.GetEditControl as TAdvSearchEdit).Items[index].Tag; // the t variable holds the unique ID of the selected item via the TAdvSearchEdit end;