Best practice on simple DBAdvGrid handling

Dear all,

I fumbled a while with DBAdvGrid and AnyDac TAdQuery, to get some most easy drop and play components
that serves my needs for a custom user interface.
But I found many properties not doing as expected, and I'm asking maynbe i'm doing something wrong here.

Here is my plan:
- use AnyDac TAdQuery as universal datasource
- use a descendant from TDBAdvGrid to customize the desired behaviour and settings:
  - automatically use special editors according the underlying TFields datatype
  - all field editors behave in the same (Excel-friendly) way, like
     * enter edit with RETURN key
     * enter CRLF lines within the memo by pressing Ctrl-Enter
     * leave and save the edit with RETURN key
     * leave and discard changes with ESC key
- the row-height should autosize according the multi-line MEMO fields on data load, so
  that they are always nicely visible.
  Maybe with programatically setable max-autosize height.
- standard use of special popup-editors, like TCalender,
     * RETURN key will enter inplace editor, 
     * pressing INSERT during inplace editing, will open the more comfortable popup-version
     * leave and save the popup-edit with RETURN key

     * leave and discard changes with ESC key
- moreover the components shall write all changes to DB, and also the refresh, display, etc. should behave like
- Completely usable via keys only, for large data-entry tasks, the mouse options are still necessary too of course.
  (e.g. opening popup-editors or LookupCombos with INS key instead of  mouse-press).

e.g. for memo fields (blob subtype 1), i've tried many ways, like a Popup TAdvMemo on a FormControlEditLink ,
setting different Editor types, using different Colums datatypes, etc.

To be honest I tried many different ways to do this, as I thought simple configuration task, and I
run into several different problems (not able to popup on RETURN or INSERT key, wrong refresh,
wrong DB update, no way to update row-hieghts according to memofields during load (I use OnSelectionChanged now) etc.).
Probably I will give up soon, and will try my luck with DevExpress grid.
I think a MegaGrid like TDBAdvGrid should offer this simple behaviour options on some property settings, and not with so much effords and doesn't of Event functions at each Instance of the components.

I hope somebody hassome more experience and can recommend some best practices and tips how
to make a TDBAdvGrid component more convenient, so that it is really solving the 99% of standard tasks.

Best regards



I'm not sure why you need to use an external editor for this.
Set grid.MultiLineCells = true and optionally grid.SizeWhileTyping.Height = true and the grid should do the editing of memos.

For a popup calendar, use the edDateEdit editor type.
The grid is usable via keys, with above settings it will update, refresh the DB etc..

Dear Bruno,

thanks for the proposals, but I'm afraid that the desired behaviour is not so easy to reach.
I cannot use e.g. Popup MemoEdits without using the mouse either to show or to confirm.
And the Memo is just an example, as I 'm looking for similar behaviour in other standard editors and
lookup-boxes too.

Moreover the automatic display of the automatic selection of the Editor type doesn't work well for me.
The solution is to manage many properties to bring it to life, moreover I need to use settings in the colums items,
which means I have to create them in designtime.
And probably there is more to do in several Event functions.

If I use different EditLinks there is another level of complexity.

Exactly that is what I want to avoid, and to create a pre-defined descendant of TDBadvGrid that does everything as I usually expect (normally I need no changes to standard editor behaviours, like DateTime, Memo, etc.).
In my dreams this customized single-component should work like drag and Drop, with just a connection of the DataSource and everything behaves fine for me.  RAD at its best :-)

Maybe I understand your concept wrong, but it didn't seem to work for me well.

I tested on RAD2010, and just today I made another attempt on a quite fresh RAD2011 installation.
It seems to produce errors, like not correctly refreshed rows, etc.

I use a descendant, and tweeze some properties at Create, and also try to use a local MemoLink as example:

constructor TS4DBGrid.Create(AOwner : TComponent);
  inherited Create(AOwner);

  // Prepare MemoEdit, for perfect S4 behaviour (Return in, return out)
  FMemoEditLink := TMemoEditLink.Create(AOwner);
  FMemoEditLink.EditStyle        := esPopup;
  FMemoEditLink.AutoPopupWidth   := True;
  FMemoEditLink.PopupWidth       := 150; // Prepare Defailt H/W
  FMemoEditLink.PopupHeight      := 150;
  FMemoEditLink.WantKeyLeftRight := True;
  FMemoEditLink.WantKeyUpDown    := True;
  FMemoEditLink.WantKeyHomeEnd   := True;
  FMemoEditLink.WantKeyPriorNext := False;
  FMemoEditLink.WantKeyReturn    := False;
  FMemoEditLink.WantKeyEscape    := True;
//  FMemoEditLink.Color            := clNone;
//  FMemoEditLink.Scrollbars       := ssBoth;
//    MaxLength = 0
  FMemoEditLink.SelectAll        := False;
  FMemoEditLink.TabIsExit        := True;
  FMemoEditLink.WantReturns      := False;
  FMemoEditLink.WantTabs         := True;

  FS4AutoMemo                    := True;  // S4: Default use AutoMemo Display

  // Setup new S4 Default settings
  EditPostMode   := epRow;  // Only post afer ROW changed
  ActiveCellShow := True;
  ActiveRowShow  := True;

  Look           := glTMS;

  Navigation.AllowInsertRow    := True;
  Navigation.AllowDeleteRow    := True;
  Navigation.AppendOnArrowDown := True;

  Options := Options + [goRowSizing, goColSizing, goEditing, goThumbTracking, goDrawFocusSelected];

  SelectionRectangle           := True;
  SelectionResizer             := True;
  ShowBooleanFields            := True;
  ShowMemoFields               := True;
  ShowUnicode                  := True;
  ShowModified.Enabled         := True;

  //SizeWithForm                 := True;


procedure TS4DBGrid.GetCellEditor(ACol: Integer; ARow: Integer;  var AEditor: TEditorType);

  // Prepare for Perfect S4 MemoDisplay

  if FS4AutoMemo then
    if (Columns[ACol].Field <> nil) and
        ( (Columns[ACol].Field.DataType = ftMemo) or
          (Columns[ACol].Field.DataType = ftWideMemo)
        ) then

//      AEditor := edCustom;
//      FMemoEditLink.PopupWidth  := Self.Columns[ACol].Width;
//      if Self.RowHeights[ARow] > FMemoEditLink.PopupHeight then
//        FMemoEditLink.PopupHeight := Self.RowHeights[ARow];
//      Self.EditLink := FMemoEditLink;

      if Assigned(OnGetEditorType) then  // Overwrite, if Necessary



  inherited GetCellEditor(ACol, ARow, AEditor);


function  TS4DBGrid.SelectCell(ACol: Integer; ARow: Integer): Boolean;
  iL: Integer;
  iH: Integer;

  Result := inherited SelectCell(ACol, ARow);

  // Prepare for Perfect S4 MemoDisplay

  if FS4AutoMemo then

    if ARow >= Self.FixedRows then

      iL := S4StrLineCount( Self.Cells[ACol, ARow] );

      iH := Self.Canvas.TextHeight('M') + 2;

      if iL > 1 then
        Self.RowHeights[ARow] := iL * iH
        Self.RowHeights[ARow] := Self.DefaultRowHeight;




This approach shows many practical problems, and even I canot get the desired keylogic behaviour of the cells
(ENTER-EDIT-ENTER), like it is done in Excel-cells.
For any other special functions I'm not asking now, but this seems simple enough for me to be able to get running.

It seems that TDBAdvGrid is not well prepared to make own components, or I make something completely
wrong here.
I found many points in sourcecode which makes the live of component creation much harder, e.g.  the sequence of KeyDown handling is not easy to circumvent in the derived component class, missing important virtual functions,
Actually I don't want to change code in TDBAdvGrid itself, to stay update-friendly, but I'm afraid I have to,
if I want to achieve my goals.

If it should be really easy like 1-2-3, as you propose, maybe you have a short example for me how this can be running.

I will check the MultiLineCells property tomorrow, but I think I already did this before.


The problem here is that what you understand as the "ideal" component that you should get when you drag it on the form, is that it is very likely that this doesn't offer what other users are, hence, the component needs the ability to be customizable via properties and events. 

From this description here, it is very hard to deduct what exact feature set you need. Rather than throwing all kinds of property settings, code snippets etc... , it will be more efficient if you'd inform feature by feature what you want to achieve that you cannot get to work. Case per case isolated so it can be easily understand by both you and us.

Dear Bruno,

of course it is ideal for me, and I don't want to convince any other people to do the same.

But I plan a new larger project, which will need many simple Grids connected to Queries, and I don't want to re-configure plenty of properties each time.

By the waym with derived component I could still use most configurations, its more abour pre-set the best setup for me.

Of course I could use TFrames or nested forms, but also that approach has many drawbacks.
Why not use a customized component to do the job ?

Maybe you have a proposal, or a "best practice" how to use the components in my way.
A big problem is also false refreshing (missing lines in the display) when usng the descendant component,
what could go wrong here ?


Dear Bruno,

I tested again with your proposal.
- Used the MultiLine and AutoSize, have to set RowColSizing and Editing, etc.

After all I get a ComboBox-like Editor for the Memo field,  the main grid is not  Autosizing the RowHeight, by the way.

I cannot open the ComboBox-like Memo by any reasonable keypress, and I'm afraid also for close and save I
need the mouse again.
But it is my main user-interface goal to be used by reasonable enter key press or e.g. INS key for opening the editor.
So far I see no way to solve that easily with TDBadvGrid, or do you have any other proposal for me.