Autor Beitrag
Steffen2412
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mo 07.11.05 12:45 
Hallo,

ich habe ein StringGrid mit 3 Spalten.
Die Zellen unter den Spalten 1 und 2 sollen nicht editierbar sein.
Wenn ich auf eine Zelle unter Spalte 3 klicke sollen nur Zahlen
eingegeben werden können.


KLann mir jemand helfen wie ich das am besten mache?


Thx

Steffen
svennissel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mo 07.11.05 14:16 
Das ist entwas schwerer.
ich habe es so gemacht:
Mit dem Event OnSelectCell folgende Function gestartet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TFrame123.schreibschutz(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin

  if isLockedCell(ACol,ARow) then
  begin
    StringGridArbeitsschritteKosten.Options := StringGridArbeitsschritteKosten.Options - [goEditing];
  end else
     StringGridArbeitsschritteKosten.Options := StringGridArbeitsschritteKosten.Options + [goEditing];

end;

Dann wollte ich aber die Zellen auch noch grau haben:
Dazu das Event OnDrawCell:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TFrame123.grauFaerben(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if isLockedCell(ACol,ARow) then
  begin
    with StringGridArbeitsschritteKosten do
    begin
      Canvas.Brush.Color := clBtnFace;
      Canvas.FillRect(Rect);
      Canvas.TextOut(Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]);
    end;
  end;  
end;


isLockedCell(col:Integer,row:Integer):Boolean ist eine function die zurückgibt welche Zellen gesperrt werden sollen.
svennissel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mo 07.11.05 14:23 
Zu den Zahlenproblem: du kannst in die schreibschutz Funktion so etwas wie
ausblenden Delphi-Quelltext
1:
2:
if isNumeric(StringGrid123.Cells[Acol,arow]) then
...

einfügen.

Die Funktion dazu:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Function isNumeric(s: String): Boolean;
  var
 i : Integer;
begin
 if s = '' then
 begin
  result := false;
  exit;
 end;
 i := 1;
 result := True;
 while (i <= Length(s)) and ( (s[i] in ['0'..'9']) OR (s[i] = DecimalSeparator) ) do
 begin
   Inc(i);
 end;
 if (i <= Length(s)) and (Not ( (s[i] in ['0'..'9']) OR (s[i] = DecimalSeparator) )) then
      result := False;
END;
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 07.11.05 14:38 
ab delphi 5 mit TryStrToInt()


Good Luck

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Steffen2412 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mo 07.11.05 16:00 
ok danke euch für die schnelle hilfe