Add DBLookupCombobox to Delphi DBGrid -


i'd add dblookupcomboboxes columns in dbgrid. there nice article on about.com on how here. problem table having many columns, if select dblookupcombobox in 1 column , try scroll left, combobox move left shown in included images. how can about.com code can changed prevent behavior? web search showed 2 others complaining of exact same problem no solution. note want use dblookupcombobox show name enter id, using simple picklist not do.

using combobox scroll left

procedure tform1.dbgrid1colexit(sender: tobject); begin   if dbgrid1.selectedfield.fieldname = dblookupcombobox1.datafield     dblookupcombobox1.visible := false end;  procedure tform1.dbgrid1drawcolumncell(sender: tobject; const rect: trect;   datacol: integer; column: tcolumn; state: tgriddrawstate); begin   if (gdfocused in state)   begin     if (column.field.fieldname = dblookupcombobox1.datafield)     dblookupcombobox1     begin       left := rect.left + dbgrid1.left + 2;       top := rect.top + dbgrid1.top + 2;       width := rect.right - rect.left;       width := rect.right - rect.left;       height := rect.bottom - rect.top;        visible := true;     end;   end end;  procedure tform1.dbgrid1keypress(sender: tobject; var key: char); begin   if (key = chr(9)) exit;    if (dbgrid1.selectedfield.fieldname = dblookupcombobox1.datafield)   begin     dblookupcombobox1.setfocus;     sendmessage(dblookupcombobox1.handle, wm_char, word(key), 0);   end end;  procedure tform1.formcreate(sender: tobject); begin  dblookupcombobox1  begin    datasource := datasource1; // -> adotable1 -> dbgrid1    listsource := datasource2;    datafield   := 'resource_id'; // adotable1 - displayed in dbgrid    keyfield  := 'id';    listfield := 'resource_name; id';     visible    := false;  end;   datasource2.dataset := adoquery1;   adoquery1.connection := adoconnection1;  adoquery1.sql.text := 'select id,resource_name resources';  adoquery1.open; end; 

here 1 solution using neat hack françois.

type     // hack redeclare tdbgrid here without the form designer going mad     tdbgrid = class(dbgrids.tdbgrid)       procedure wmhscroll(var msg: twmhscroll); message wm_hscroll;     end;    tform1 = class(tform) [...] procedure tdbgrid.wmhscroll(var msg: twmhscroll); begin   if form1.dbgrid1.selectedfield.fieldname = form1.dblookupcombobox1.datafield begin     case msg.scrollcode of       sb_left,sb_lineleft,sb_pageleft: begin         form1.dbgrid1.selectedindex := form1.dbgrid1.selectedindex-1;         form1.dblookupcombobox1.visible := false;       end;       sb_right,sb_lineright,sb_pageright: begin         form1.dbgrid1.selectedindex := form1.dbgrid1.selectedindex+1;         form1.dblookupcombobox1.visible := false;       end;     end;   end;   inherited; // keep expected behavior end; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -