Ho provato a guardare in giro ma non riesco proprio a risolvere il problema: in una StrinGrid editabile quando inserisco dei valori ad esempio nella cella 1,1 il testo viene
assegnato ad una variabile e premendo "enter" (o invio) invece di passare alla cella
successiva, vorrei che il focus si spostasse nella cella +2; ecco il codice di esempio:
procedure TForm1.StringGrid1EditingDone(Sender: TObject);
var cl,rg:integer;
a:string;
begin
cl:=StringGrid1.Col;rg:=StringGrid1.row;
if cl=1 then begin
a:=StringGrid1.Cells[cl,rg];
cl:=3;
Stringgrid1.Col:=cl;StringGrid1.Row:=rg;
StringGrid1.SetFocus;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Stringgrid1.col:=1;Stringgrid1.row:=1;
stringgrid1.setfocus;
end;
per prima cosa all'apertura della Form il focus mi va nella colonna 3 (anzichè in 1); poi quando edito la cella 1,1 mi va sulla 2,1 anzichè 3,1;
proprio non riesco a comprendere :-[
grazie a chi mi vorrà illuminare, sarà anche una banalità ma non ne esco.
Hai provato così, segue esempio:
StringGrid1.Row:=20;
StringGrid1.Col:=5;
StringGrid1SelectCell(self,20,5,cansel);
StringGrid1.SetFocus;
Mi riporta questi errori:
"unit1.pas(37,5) Note: Local variable "a" is assigned but never used
unit1.pas(60,48) Error: Identifier not found "cansel"
unit1.pas(74) Fatal: There were 1 errors compiling module, stopping"
procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
var cl,rg:integer;
a:string;
begin
cl:=StringGrid1.Col;rg:=StringGrid1.row;
if cl=1 then begin
a:=StringGrid1.Cells[cl,rg];
cl:=3;
Stringgrid1.Col:=cl;StringGrid1.Row:=rg;
StringGrid1SelectCell(self,cl,rg,cansel);
StringGrid1.SetFocus;
end;
end;
avevo già provato perchè facendo una ricerca sul forum veniva suggerito di utilizzare
questa funzione (SelectCell);
Ecco qua, grazie in anticipo !
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;
type
{ TForm1 }
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormShow(Sender: TObject);
procedure StringGrid1EditingDone(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.StringGrid1EditingDone(Sender: TObject);
var cl,rg:integer;
a:string;
begin
cl:=StringGrid1.Col;rg:=StringGrid1.row;
if cl=1 then begin
a:=StringGrid1.Cells[cl,rg];
cl:=3;
Stringgrid1.Col:=cl;StringGrid1.Row:=rg;
StringGrid1.SetFocus;
end;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
var cl,rg:integer;
a:string;
begin
cl:=StringGrid1.Col;rg:=StringGrid1.row;
if cl=1 then begin
a:=StringGrid1.Cells[cl,rg];
cl:=3;
Stringgrid1.Col:=cl;StringGrid1.Row:=rg;
StringGrid1SelectCell(self,cl,rg,canselect);
StringGrid1.SetFocus;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Stringgrid1.col:=1;Stringgrid1.row:=1;
stringgrid1.setfocus;
end;
end.
ti ringrazio, il tuo funziona (ovviamente), io ho apportato alcune modifiche che
servivano per il tipo di lavoro che devo fare e purtroppo non mi da il risultato
sperato :'(
Se inserisco un testo alla cella 1,1 mi deve dare un testo + una stringa (che prelevo da un dbase) nella cella 2,1 saltare quella maledetta cella ed andare direttamente alla cella 3,1, invece niente mi resta sulla 2,1.
Ti allego anche il sorgente se hai tempo e voglia di dare un'occhiata, altrimenti
grazie comunque sei sempre gentile
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure StringGrid1EditingDone(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormShow(Sender: TObject);
begin
Stringgrid1.col:=1;
Stringgrid1.row:=1;
StringGrid1.SetFocus;
end;
procedure TForm1.StringGrid1EditingDone(Sender: TObject);
var cl,rg:integer;
a:string;
variabile: boolean;
begin
cl:=StringGrid1.Col;rg:=StringGrid1.row;
if cl=1 then begin
a:=StringGrid1.Cells[cl,rg];
a:=a+'prova';inc(cl);
StringGrid1.Cells[cl,rg]:=a;inc(cl);
StringGrid1.Col:=cl;StringGrid1.Row:=rg;
Stringgrid1.OnSelectCell(self, cl, rg, variabile);
Stringgrid1.SetFocus;
end;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
var
variabile: boolean;
begin
end;
end.