Author Topic: Autocomplete a lookup field in Dbgrid  (Read 449 times)


  • New Member
  • *
  • Posts: 33
Autocomplete a lookup field in Dbgrid
« on: April 27, 2021, 07:01:07 pm »
I copied this topic form

I have a a dataset with a lookup field.
I edit it with a dbgrid.
The grid correctly uses a picklist for that field, but I couldn't find
an easy way to autocomplete it (i.e. allow the user to type the first
few characters of the value to select an entry).
The problem seems to be that the picklist field uses a
TPickListCellEditor which derives from a TCustomComboBox that doesn't
implement such functionality (it does but only to set the text in case
it's a csDropDownList, it doesn't set the selected item).
I see that a TDBLookupCombobox supposedly implements autocomplete (I saw
some forum post when they say it's problematic, don't know if it has
been solved now), but I cannot use it since I'm setting two fields, not one.
Any idea?

I have exactly the same problem.

I did a following change in Grids.pas, line 9229 and below

Code: Pascal  [Select][+][-]
  1. FPickListEditor.Items.Assign(C.PickList);
  2. FPickListEditor.DropDownCount := C.DropDownRows;
  3. FPickListEditor.Style := csDropDown;
  4. FPickListEditor.ItemWidth := FPickListEditor.Width*3;
  5. FPickListEditor.AutoComplete := true;
  6. FPickListEditor.AutoDropDown := True;
  7. FPickListEditor.AutoCompleteText := [cbactEnabled,   cbactEndOfLineComplete,  cbactSearchAscending];
  8. FPickListEditor.ReadOnly := False;  

Now Combo drops down automatically, but still not autocomplete.
It will not change Text propery of the TPickListCellEditor control.

But if I use normal pick list instead of LookupField, Autocomplete works perfect with changes above.

Any ideas?

Trunc, Windows 64 bit.

[Edited to add code tags - see How to use the Forum.]
« Last Edit: April 28, 2021, 02:23:03 am by trev »


TinyPortal © 2005-2018