Board index » delphi » SendMessage(myDBGrid.Handle, WM_COPY, 0, 0) doesn't work? boo hoo!

SendMessage(myDBGrid.Handle, WM_COPY, 0, 0) doesn't work? boo hoo!

I have an edit menu in my app. I need to tie the various editing options (copy paste etc) into the various
editable components. Using a modified version of the above works for TDBEdit controls  and just about
everything else but not for TDBGrid controls even though they have their own default right-click pop-up
edit menu.

Can anyone tell me what I don't know?

The TDBGrid component has no copytoclipboard method so I'm a bit stuck.
--

Greg Lorriman co. inc. & sons Ltd

 

Re:SendMessage(myDBGrid.Handle, WM_COPY, 0, 0) doesn't work? boo hoo!


Hi Greg,

The problem you are having is because the grid uses a floating
maskedit control for it's input.  This sub-control of the grid (called
TInPlaceEdit) is moved around the grid as the user needs it, so the
grid itself has no text to WM_COPY.

The solution is to get a handle to the in-place editor.  The most
reliable way to do that is to derive a new grid control and surface
the protected property InPlaceEdit, but that also has disadvantages.

I had a little play and came up with the function below.  The
InPlaceEdit is owned by the grid, and so appears in it's Components
property, which gives us one way of getting at it.  You didn't say
which version of delphi you where using, but this should work with all
versions.

function GetGridEditor(grid:TCustomGrid):TInPlaceEdit;
begin;
if grid.ComponentCount>0
  then result := (grid.Components[0] as TInPlaceEdit)
  else result := nil;
end;

you can then use it:

procedure CopyGridText;
var IPEdit:TInPlaceEdit;
begin;
IPEdit := GetGridEditor(grid1);
if assigned(IPEdit) then SendMessage(IPEdit.handle,WM_COPY etc..
...

Hope that helps.

Eamonn Mulvihill
Consultancy and programing services
-----------------------------------
Update Computer Services
Kent, England
u...@cableinet.co.uk
http://wkweb5.cableinet.co.uk/ucs/index.htm

Re:SendMessage(myDBGrid.Handle, WM_COPY, 0, 0) doesn't work? boo hoo!


I know.

I my self uses TEdit and copy the text from TDBEdit and makes the TDBEdit
invisable. You have to copy the text onActivate message.

Quote
Greg Lorriman wrote in message <673829430...@lorriman.demon.co.uk>...

>I have an edit menu in my app. I need to tie the various editing options

(copy paste etc) into the various
Quote
>editable components. Using a modified version of the above works for

TDBEdit controls  and just about
Quote
>everything else but not for TDBGrid controls even though they have their

own default right-click pop-up
Quote
>edit menu.

>Can anyone tell me what I don't know?

>The TDBGrid component has no copytoclipboard method so I'm a bit stuck.
>--

>Greg Lorriman co. inc. & sons Ltd

Other Threads