Recent

Author Topic: [SOLVED] DBCombobox in DBGrid - What am I missing?  (Read 922 times)

fmc

  • New Member
  • *
  • Posts: 37
[SOLVED] DBCombobox in DBGrid - What am I missing?
« on: October 28, 2019, 05:31:59 pm »
In the FormActivate, I have:
Code: Pascal  [Select][+][-]
  1.   DM1.DS_UnitComboBox.DataSet := DM1.ZQ_UnitComboBox;
  2.   DM1.ZQ_UnitComboBox.Connection := DM1.ZConn
  3.   RxUnitComboBox.DataSource := DM1.DS_UnitComboBox;
  4.  
  5.   with RxUnitComboBox do
  6.   begin
  7.     DataField := 'inventory_unit';
  8.     Visible:= False;
  9.   end;

For the DBGrid, I have:
Code: Pascal  [Select][+][-]
  1. procedure TForm_Neo.RxDBGrid_AddItemsSelectEditor(Sender: TObject;
  2.   Column: TColumn; var Editor: TWinControl);
  3. begin
  4.   try
  5.     if Column.FieldName = RxUnitComboBox.DataField then
  6.       begin
  7.         Editor := RxUnitComboBox;
  8.       end;
  9.   except
  10.     On e: Exception do
  11.        MessageDlg('Error during TForm_Main.DBGrid_AddItemsSelectEditor event: ' +
  12.                          e.Message, mtWarning,[mbOK],0);
  13.   end;
  14.   Editor.BoundsRect := RxDBGrid_AddItems.SelectedFieldRect;
  15. end;

For the DBCombobox (Style := csDropDown):
Code: Pascal  [Select][+][-]
  1. procedure TForm_Neo.RxUnitComboBoxKeyPress(Sender: TObject; var Key: char);
  2. begin
  3.   if key = #13 then
  4.     try
  5.       if RxDBGrid_AddItems.SelectedIndex + 1 < RxDBGrid_AddItems.Columns.Count then
  6.         RxDBGrid_AddItems.SelectedIndex := RxDBGrid_AddItems.SelectedIndex + 1;
  7.     except
  8.       On e: Exception do
  9.         MessageDlg('Error during TForm_Neo.RxUnitComboBoxKeyPress event: ' +
  10.                          e.Message, mtWarning,[mbOK],0);
  11.     end;
  12. end;
And I get no DBCombobox in the DBGrid. I can enter data in the cell and it gets saved. But I just don't get the DBCombobox.

But, if I change the DBGrid code to
Code: Pascal  [Select][+][-]
  1. procedure TForm_Neo.RxDBGrid_AddItemsSelectEditor(Sender: TObject;
  2.   Column: TColumn; var Editor: TWinControl);
  3. begin
  4.   try
  5.     if Column.Field = RxUnitComboBox.Field then  // NOTE THE CHANGE TO THIS LINE
  6.       begin
  7.         Editor := RxUnitComboBox;
  8.       end;
  9.   except
  10.     On e: Exception do
  11.        MessageDlg('Error during TForm_Main.DBGrid_AddItemsSelectEditor event: ' +
  12.                          e.Message, mtWarning,[mbOK],0);
  13.   end;
  14.   Editor.BoundsRect := RxDBGrid_AddItems.SelectedFieldRect;
  15. end;
then I get a DBCombobox in the Grid. But it accepts no data. No matter what I type in it, it gets wiped out when I exit the cell.
« Last Edit: October 28, 2019, 05:47:08 pm by fmc »
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

fmc

  • New Member
  • *
  • Posts: 37
Re: DBCombobox in DBGrid - What am I missing?
« Reply #1 on: October 28, 2019, 05:46:44 pm »
HA! Got it! I had it wired in to the wrong Datasource   :D
Code: Pascal  [Select][+][-]
  1.   DM1.DS_UnitComboBox.DataSet := DM1.ZQ_UnitComboBox;
  2.   DM1.ZQ_UnitComboBox.Connection := DM1.ZConn
  3.   // RxUnitComboBox.DataSource := DM1.DS_UnitComboBox;
  4.   RxUnitComboBox.DataSource := DM1.DS_AddItems;
  5.   with RxUnitComboBox do
  6.   begin
  7.     DataField := 'inventory_unit';
  8.     Visible:= False;
  9.   end;
Win X Pro / Lazarus 2.0.6 / FPC 3.0.4

 

TinyPortal © 2005-2018