drawing a dbgrid cell from a look up lazarus / 16-Databases ---------------------------------------------------------------------- codifies · 2012-09-11 05:07 I have managed to use a DBLookupComboBox as a custom editor for a field containing a foreign key. this works (but I can't see how to change the width of the drop down bit of the combo box which is way to big compared to the cell and means you cant see the value properly when closed) My main issue is the cell renders the key text (i want to be editing a key value but display it as the looked up text associated with the key in the foreign table) I've got as far of attempting to render some custom text in the cell like this Code: [Select]procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;   DataCol: Integer; Column: TColumn; State: TGridDrawState); var   s: String; begin   if (gdFocused in State) then FRect := Rect;   if (Column.DesignIndex=3) then      begin          s:='arrgh! :)';          (Sender as TDBGrid).Canvas.TextRect(Rect,Rect.Left,Rect.Top, s);      end   else       (Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State); end;    is there some way I can set the string by looking up the value via the DBLookupComboBox somehow? or do I need to make a seperate sql query for each cell? With luck I'm doing this the hard way and there's a dead easy way! ---------------------------------------------------------------------- teos · 2012-09-13 18:12 I'm not sure if I understand the problem but DBgrid should be able to display and use the dbLookupcombobox. But to get that to work, you should add a field to the fielddefs of the dataset, defining that field as lookup. Then you fill in the lookupdataset, lookupkeyfield, resultfield and from that point, DBGrid should show a combobox for the field. I think, also from your other question that the components you use provide much more functionality than you think they do. Those dbLookupcomboboxes are part of the database framework. If my remarks don't work like they should, I'm very curious to learn what the problem is and if you can post the settings of the datafield that you need the lookupcombobox for. ---------------------------------------------------------------------- codifies · 2012-09-13 18:44 I discovered later that you didn't need a separate drop down, you used to need to in Delphi years ago I seem to remember and I'm only just getting back into things I attempted to get the approach you suggested working earlier, but could only get the drop down bit working but not the cell display.  Eventually on each run it just said some data component wasn't active without identifying which component it was, and I couldn't resurrect it and ended up used a different approach...  If you're confident you can replicate a foreign key look up to edit a dbgrid table I'm positive not only myself but quite a large number of people would find it useful.