Page 1 of 1

How copy selection in TChartGrid to clipboard

Posted: Wed Mar 02, 2016 9:58 pm
by 5886551
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

Re: How copy selection in TChartGrid to clipboard

Posted: Thu Mar 03, 2016 11:11 am
by yeray
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;

Re: How copy selection in TChartGrid to clipboard

Posted: Fri Mar 04, 2016 5:47 pm
by 5886551
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

Re: How copy selection in TChartGrid to clipboard

Posted: Sun Mar 06, 2016 8:48 pm
by 5886551
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

Re: How copy selection in TChartGrid to clipboard

Posted: Mon Mar 07, 2016 9:13 am
by yeray
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