Recent

Author Topic: [SOLVED] Disappearing data in TRxDBGrid that uses TDBLookupComboBox  (Read 1677 times)

guest48180

  • Guest
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 now fails. 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 the TRxDBGrid and the Laz DBLookupComboBox. The TRxDBGrid is more robust than Lazarus' stock DBGrid, so I'd like to be able to use it.

What happens when I use the tutorial code with the TRxDBGrid is incredible. I have 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, my data magically appearing. But when I'd move to another cell, it'd disappear again.
Code: Pascal  [Select][+][-]
  1. procedure TForm_Main.DBGrid_AddItemsDrawColumnCell(Sender: TObject;
  2.   const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
  3. begin
  4.   if (gdFocused in State) then
  5.   begin
  6.     if (Column.Field.FieldName =  DBLookupComboBox_InventoryUnit.DataField) then
  7.     with DBLookupComboBox_InventoryUnit do
  8.     begin
  9.       Left := Rect.Left + DBGrid_AddItems.Left + 2;
  10.       Top := Rect.Top + DBGrid_AddItems.Top + 2;
  11.       Width := Rect.Right - Rect.Left;
  12.       Width := Rect.Right - Rect.Left;
  13.       Height := Rect.Bottom - Rect.Top;
  14.       Visible := True;
  15.     end;
  16.   end
  17. end;

I use several other of these TRxDBGrids, less the DBLookupComboBox, and they work like a DBGrid's suppose to. Even the Grid in question works, right up until I wire in the above-noted procedure. Then it all falls apart. Obviously I'm not smart enough to understand why that procedure works with Lazarus' stock TDBGrid and TDBLookupComboBox and craps out with the TRxDBGrid and a TDBLookupComboBox.

I hope someone can/will explain to me why my data's disappearing from the grid when i use that procedure? Thanks.

**************************************************************************************************************************************

Components in question are:
TRxDBGrid
TDBLookupComboBox

guest48180

  • Guest
Re: Disappearing data in TRxDBGrid that uses TDBLookupComboBox
« Reply #1 on: September 21, 2019, 06:20:34 am »
I didn't understand a lick he said! But his vid was of good quality, and his approach to planting DBLookupComboBoxes inside DBGrid cells is much cleaner than the tutorial on the same.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: [SOLVED] Disappearing data in TRxDBGrid that uses TDBLookupComboBox
« Reply #2 on: September 21, 2019, 11:29:56 am »
I think using the OnColumnDraw event to add a special editor to a DBGrid is wrong - this is Delphi code. In Lazarus, the grids are much more advanced than in Delphi, and you have the event OnSelectEditor to replace the cell editor. See the similar discussion in https://forum.lazarus.freepascal.org/index.php/topic,43416.msg332556.html#msg332556.

guest48180

  • Guest
Re: [SOLVED] Disappearing data in TRxDBGrid that uses TDBLookupComboBox
« Reply #3 on: September 21, 2019, 12:15:00 pm »
The guy in the video, also working with Lazarus, used the OnSelectEditor instead of OnColumnDraw. My DBgrid and DBComboBox are working well, now. I wish there were more videos like that, except maybe in English instead of Turkish...or whatever that guy was speaking. Hats off to him, though!

And thanks for the feedback, wp. I appreciate you for that.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: [SOLVED] Disappearing data in TRxDBGrid that uses TDBLookupComboBox
« Reply #4 on: September 21, 2019, 12:24:01 pm »
The guy in the video, also working with Lazarus, used the OnSelectEditor instead of OnColumnDraw.
Sorry for the duplication then, I was not watching in full this almost 40 minutes of video in a language that I don't understand.

guest48180

  • Guest
Re: [SOLVED] Disappearing data in TRxDBGrid that uses TDBLookupComboBox
« Reply #5 on: September 21, 2019, 01:37:42 pm »
No problem, man. I cldn't understand the guy either. So I muted him and just followed along. Monkey see. Monkey do  :D

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: [SOLVED] Disappearing data in TRxDBGrid that uses TDBLookupComboBox
« Reply #6 on: September 21, 2019, 03:38:24 pm »
I think using the OnColumnDraw event to add a special editor to a DBGrid is wrong - this is Delphi code. In Lazarus, the grids are much more advanced than in Delphi, and you have the event OnSelectEditor to replace the cell editor. See the similar discussion in https://forum.lazarus.freepascal.org/index.php/topic,43416.msg332556.html#msg332556.
I always say that Lazarus is much more than just a Delphi clone.

 

TinyPortal © 2005-2018