Recent

Author Topic: TStringGrid - previous position of selected cell  (Read 5724 times)

bedla

  • Newbie
  • Posts: 2
TStringGrid - previous position of selected cell
« on: December 10, 2007, 12:02:23 pm »
Hi, I need help. I want to check a value in a cell of a stringgrid (in editing mode).  I write some numbers to the cell and then I click to another cell. Now, I need to check a content of the previous cell if one contains the right value (e.g. > 0). How do I find out corodinates of the previous cell after click to another cell and to choose previous cell again?  I tried to get it in evetns editingdone, selectcell, but without avail.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8319
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: TStringGrid - previous position of selected cell
« Reply #1 on: December 10, 2007, 12:25:44 pm »
Well, just prepare 2 variables of Integer that saves the latest cell coordinates. For example:
Code: [Select]

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Grids,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Label1: TLabel;
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

var
  PrevCol,PrevRow: Integer;

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  PrevCol:=0;
  PrevRow:=0;
end;

procedure TForm1.StringGrid1Click(Sender: TObject);
begin
  Label1.Caption:='PrevCol: '+IntToStr(PrevCol)+
                 ' PrevRow: '+IntToStr(PrevRow);
  PrevCol:=StringGrid1.Col;
  PrevRow:=StringGrid1.Row;
end;

initialization
  {$I Unit1.lrs}

end.

See the changes in the Label1.

bedla

  • Newbie
  • Posts: 2
Re: RE: TStringGrid - previous position of selected cell
« Reply #2 on: December 10, 2007, 10:53:07 pm »
Thanks. It helped me.  :)

 

TinyPortal © 2005-2018