Following this tutorial, I've been able to use the DB components that come with Lazarus and placing a DBLookupComboBox inside a DBGrid has always worked seamlessly. But a few days ago, I switched to Rx DB components and the same tutorial code fails now. And since there are properties in the standard Lazarus DBLookupComboBox that aren't in the TRxDBLookupCombo, properties used in the tutorial, I've only been able to work with your grid and the Laz DBLookupComboBox. Your DBGrid is far more robust than Lazarus' stock DBGrid, so I want to use it.
What happens when I use the tutorial code with your DBGrid is incredible. I had just one row (for testing) in the table that was to load in the grid. All looked okay. But as soon as I added the code for OnDrawColumnCell, my only row of data disappeared. Now I cld double click in the cells and the data wld highlight, magically appearing. But when I'd move to another cell, it'd disappear again. And not once did the DBLookupComboBox appear in the designed cell. So I commented out Visible := False so I cld keep my eye on the DBLookuoComboBox while the program ran.
Code: Select all
with DBLookupComboBox_InventoryUnit do
begin
DataField := 'inventory_unit';
KeyField:= 'inventory_unit';
ListField:= 'inventory_unit';
ListSource := DS_LookupInventoryUnit;
DataSource := DS_AddItems;
//Visible:= False;
end;
Code: Select all
procedure TForm_Main.DBGrid_AddItemsDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (Column.Field.FieldName = DBLookupComboBox_InventoryUnit.DataField) then
with DBLookupComboBox_InventoryUnit do
begin
ShowMessage('Test');
Left := Rect.Left + DBGrid_AddItems.Left + 2;
Top := Rect.Top + DBGrid_AddItems.Top + 2;
Width := Rect.Right - Rect.Left;
Width := Rect.Right - Rect.Left;
Height := Rect.Bottom - Rect.Top;
Visible := True;
end;
end
end;
**************************************************************************************************************************************
OS: Win X Pro
Lazarus 2.0.4
FPC 3.0.4
Components in question are:
TRxDBGrid
TDBLookupComboBox (I'd rather use your TRxDBLookupCombo, but its properties differ from the tutorial)