DBGrid - sorting by LookUp or calculated column lazarus / 16-Databases ---------------------------------------------------------------------- tsr ยท 2016-02-04 13:14 1. How to sort data in DBGrid by lookup column or calculated column? I have a code to sort a column by clicking on its title. Works fine for normal fields but not for lookup. Error message: List index (-2) out of bounds. I have used the code from wiki: http://wiki.freepascal.org/How_to_write_in-memory_database_application s_in_Lazarus/FPC#Sorting_DBGrid_on_TitleClick_event_for_TBufDataSet 2. Another problem i think related to previous. When I add lookup field to SQLQuery then some other string field is not displaying data in DBGrid. Just empty field. When I remove lookup field then the other one displays correctly. If I add two lookup fields then two others fields don't display their data. It happens with PostgreSQL connection only.