Placing TRxDBLookupCombo into TRxDBGrid

In this forum you may discuss all issues concerning the Lazarus IDE and Freepascal (both running on Windows or Linux).

Moderators: gto, cipto_kh, EgonHugeist

Locked
Slyde
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 20.09.2019, 21:55

Placing TRxDBLookupCombo into TRxDBGrid

Post by Slyde »

Hello Forum:

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;
I cld see it when I ran the program. But my data was still invisible. So I placed a ShowMessage() in the OnDrawColumnCell procedure and your DBGrid started destroying itself on every call to ShowMessage(). Craziest thing I ever saw!

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; 
I need some help with this. Thanks.

**************************************************************************************************************************************
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)
You do not have the required permissions to view the files attached to this post.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1935
Joined: 17.01.2011, 14:17

Re: Placing TRxDBLookupCombo into TRxDBGrid

Post by marsupilami »

locked on request because it is off topic ;)
Locked