I have altered a D6 stringgrid to allow for left or right justified checkboxes to be displayed in the grid cells. When the stock inplace editor is called the edit box for receiving data starts at the beginning of the cell and its width covers the entire width of the cell (ie it fills the cell completely covering my checkboxes until repainted). How can I implement my own inplace editor and control the starting location of the editor and its width? Thanks in advance to all. Bill

1

There are 1 best solutions below

5
On BEST ANSWER

TStringGrid does not natively support what you are asking for. The coordinates of the inplace editor are fixed to the entire cell bounds, as it was never designed to take user-defined cell controls into account.

When TStringGrid positions the editor, it calls CellRect() (which is not virtual) and passes the returned TRect to TInplaceEdit.Move() (which is not virtual), which calls TInplaceEditor.InternalMove() (which is private) to move the editor HWND to the specified coordinates and size using the Win32 API SetWindowPos() function.

The only way you will be able to change that logic is to either:

  1. make a copy of Grids.pas and alter TStringGrid's source code, then add the modified file to your project (this only works if Runtime Packages are disabled).

  2. use a hook/detour to redirect TInplaceEdit.Move() to a custom method where you can alter the content of the TRect before passing it to the original implementation.

Update: now that I think more about it, you might be able to derive a class from TInplaceEdit and override its virtual WndProc() method to calculate different position/size information when asked by the WM_GETMINMAXINFO or WM_WINDOWPOSCHANGING message. Or override its virtual BoundsChanged() method to reposition/resize the editor after the grid has positioned/sized the editor where it wants. Either way, you can override the virtual TStringGrid.CreateEditor() method to make the grid create an instance of your editor class.