How copy selection in TChartGrid to clipboard

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Rolf Fankhauser
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

How copy selection in TChartGrid to clipboard

Post by Rolf Fankhauser » Wed Mar 02, 2016 9:58 pm

Hi

I use a chart to show some series and a chart grid to show the values of the series. Now I would like to copy the selection to the clipboard if the user has selected some rows and columns of the chart grid. There is a complication that I hide some columns by setting the width to zero and I don't want that these colums are copied.
I could read begin and end of rows and columns with Selection.Rigth, Left, Top and Bottom but I don't see how to access the values in the cells. I guess that I have to access the corresponding series and use XValue and YValue.

Thanks, Rolf

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How copy selection in TChartGrid to clipboard

Post by Yeray » Thu Mar 03, 2016 11:11 am

Hello,

You can use a helper to access the protected GetEditText(ACol,ARow) function:

Code: Select all

type TCustomChartGridHelper = class helper for TCustomChartGrid
  public
    function GetText(ACol, ARow: Integer): String;
end;

function TCustomChartGridHelper.GetText(ACol, ARow: Integer): String;
begin
  result:=GetEditText(ACol,ARow);
end;
Then you'll be able to do later:

Code: Select all

procedure TForm1.ChartGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var i: Integer;
    tmpS: string;
begin
  tmpS:='';

  if (ssCtrl in Shift) and (Key=Ord('C')) then
  begin
    for i:=0 to Length(selectedCells)-1 do
      tmpS:=tmpS + ' ' + ChartGrid1.GetText(selectedCells[i].X, selectedCells[i].Y);

    ShowMessage(tmpS);
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Rolf Fankhauser
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

Re: How copy selection in TChartGrid to clipboard

Post by Rolf Fankhauser » Fri Mar 04, 2016 5:47 pm

Thanks Yeray for the prompt answer!

But I don't know how to define a helper class under C++.
I need to code in C++ with C++Builder.

I will see if I can find a workaround to access the protected GetText(ACol,ARow) function under C++.

I could not find a method GetText in the header file TeeChartGrid.hpp. Is it GetEditText? Because at the beginnning you wrote GetEditText but GetText in the code.
Also, I could not find a property selectedCells (looks like Java code definition). Do you mean Selection?

Rolf

Rolf Fankhauser
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

Re: How copy selection in TChartGrid to clipboard

Post by Rolf Fankhauser » Sun Mar 06, 2016 8:48 pm

I found a workaround for C++:

I edited the header file TeeChartGrid.hpp and moved
DYNAMIC AnsiString __fastcall GetEditText(int ACol, int ARow);
from protected to public.

Then the compiler didn't complain anymore that GetEditText is not accessible.
Surprisingly the linker didn't complain and the code works fine!
But are there any drawbacks by this hack? I'm surprised that this is working!!

Why is GetEditText protected?

Regards, Rolf

Yeray
Site Admin
Site Admin
Posts: 9534
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How copy selection in TChartGrid to clipboard

Post by Yeray » Mon Mar 07, 2016 9:13 am

Hello Rolf,
Rolf Fankhauser wrote: But I don't know how to define a helper class under C++.
I need to code in C++ with C++Builder.
Looking at this, I'm not sure if this is possible in C++.
Rolf Fankhauser wrote:I could not find a method GetText in the header file TeeChartGrid.hpp. Is it GetEditText? Because at the beginnning you wrote GetEditText but GetText in the code.
The TCustomChartGridHelper helper I defined declares the method GetText (it could be any name of your choice) and it calls the protected method GetEditText.
Rolf Fankhauser wrote:Also, I could not find a property selectedCells (looks like Java code definition). Do you mean Selection?
selectedCells was an array of points (int, int) I used to test that. The intention is to store the row and column of the selected cells. You could use OnMouseDown to populate that array (adding or removing points to it) when a cell is clicked (probably when Ctrl key is also pressed).
Rolf Fankhauser wrote:Then the compiler didn't complain anymore that GetEditText is not accessible.
Surprisingly the linker didn't complain and the code works fine!
But are there any drawbacks by this hack? I'm surprised that this is working!!
If that works I don't see any problem with that.
Rolf Fankhauser wrote:Why is GetEditText protected?
It overrides the GetEditText protected method from its parent, the TCustomGrid:
http://docwiki.embarcadero.com/Librarie ... etEditText
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply