Moving Cursor with StringGrid Entry...

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
tbonejo
Newbie
Newbie
Posts: 73
Joined: Wed Sep 06, 2006 12:00 am
Contact:

Moving Cursor with StringGrid Entry...

Post by tbonejo » Thu Feb 01, 2007 11:49 am

Ok, this should be neat.

I basically want to move my cursor to the point with which an entry of a number in a cell has occurred. I have all the events in place.

Do I set the YValue of the cursor to move or the XValue? Id assume the XValue but how do I calculate the position. And of course the value entered may not be the exact number available in the series, so how does that play out to get the nearest point?


Thanks,

Tom
Tom

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Feb 01, 2007 12:01 pm

Hi Tom,

You may be interested in using Locate method as shown here:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var Index: Integer;
begin
  Series1.YValues[5]:=10;

  Index:=Series1.YValues.Locate(Series1.YValues[5]);

  ChartTool1.YValue:=Series1.YValues[Index];
  ChartTool1.XValue:=Series1.XValues[Index];
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

tbonejo
Newbie
Newbie
Posts: 73
Joined: Wed Sep 06, 2006 12:00 am
Contact:

Post by tbonejo » Thu Feb 01, 2007 12:37 pm

Narcis,

Works as expected. The only thing is the numbers are somewhat long, even 1000ths of a place after the decimal. Trying to locate a number has to be exact, as far as I can tell.

Any ideas on how to locate the approximate number rather than the exact?


Thanks.

Tom
Tom

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Feb 01, 2007 1:04 pm

Hi Tom,

Then the only way I can think of is doing something like this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  i, SeriesIndex: Integer;
  Val, ApproxVal, Diff, tmpDiff: Double;

begin
  Val:=500;
  ApproxVal:=499.5;
  Series1.YValues[5]:=Val;
  Diff:=Series1.MaxYValue;
  SeriesIndex:=-1;

  for i:=0 to Series1.Count do
  begin
    tmpDiff := Series1.YValue[i] - ApproxVal;
    if Abs(tmpDiff) < Diff then
    begin
      Diff:=tmpDiff;
      SeriesIndex:=i;
    end;
  end;

  ChartTool1.YValue:=Series1.YValues[SeriesIndex];
  ChartTool1.XValue:=Series1.XValues[SeriesIndex];
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply