Q&A

  • 스트링그리드 편집
꼭 부탁드릴게요

스트링 그리드에서요 goediting했는데 마지막 col과 row는
셀렉트 못하게 막고 싶은데 이는 어떻게 하죠??


그리고 값을 00000015라고 치면 그냥 15로 바꿔서 보이게 하는건 어떻게 하나요

아무생각이 없네요 전...

그리고 엔터키쳤을때도 마지막 행으로는 가지않게 하고 싶은데 이것도 어렵네됴

꼭 가르쳐주세요~

이건 제 쏘스요~ (델마당 분들이 거의 다 해주셨지만^^;)


unit ugrade;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, Ugrade2;

type
Tfrmmain = class(TForm)
  Button1: TButton;
  Button2: TButton;
  StringGrid1: TStringGrid;
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  procedure FormCreate(Sender: TObject);
  procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
    var CanSelect: Boolean);
  procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
  

private
  { Private declarations }

public
  { Public declarations }

end;

var


frmmain : Tfrmmain;



implementation

{$R *.DFM}

procedure Tfrmmain.Button1Click(Sender: TObject);
begin
frmrep.quickrep1.preview;
end;

procedure Tfrmmain.Button2Click(Sender: TObject);
begin
frmrep.quickrep1.print;
end;

procedure Tfrmmain.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0] := '이름';
StringGrid1.Cells[1,0] := '수학';
StringGrid1.Cells[2,0] := '영어';
StringGrid1.Cells[3,0] := '과학';
StringGrid1.Cells[4,0] := '국어';
StringGrid1.Cells[5,0] := '사회';
StringGrid1.Cells[6,0] := '평균';

StringGrid1.Cells[0,1] := '철수';
StringGrid1.Cells[0,2] := '영희';
StringGrid1.Cells[0,3] := '건주';
StringGrid1.Cells[0,4] := '기훈';
StringGrid1.Cells[0,5] := '평균';
end;

function StrToFloatDef(const S: string; Default: Single): Single;
var
E: Integer;
begin
Val(S, Result, E);
if E <> 0 then Result := Default;
end;


procedure TFrmmain.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
i : integer;
begin
if Key = #13 then
begin
if StringGrid1.Col >= 5 then
   begin
   if StringGrid1.Row = StringGrid1.RowCount -1 then Exit;
   StringGrid1.Row := StringGrid1.Row + 1;
   StringGrid1.Col := 1;
   Exit;
   end;
StringGrid1.Col := StringGrid1.Col + 1;
end;

end;

procedure TFrmmain.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
i : integer;
col1, col2, col3, col4, row1, row2, row3, row4, row5 : Double;
begin
Col1 := 0; Col2 := 0; Col3 := 0; Col4 := 0;
row1 := 0; row2 := 0; row3 := 0; row4 := 0; row5 := 0;
with StringGrid1 do
  begin
  for i := 1 to 5 do
    begin
    Col1 := Col1 + StrToFloatDef(Cells[i, 1], 0);
    Col2 := Col2 + StrToFloatDef(Cells[i, 2], 0);
    Col3 := Col3 + StrToFloatDef(Cells[i, 3], 0);
    Col4 := Col4 + StrToFloatDef(Cells[i, 4], 0);
    end;
  for i:= 1 to 4 do
    begin
    row1 := row1 + StrToFloatDef(cells[1,i],0);
    row2 := row2 + StrToFloatDef(cells[2,i],0);
    row3 := row3 + StrToFloatDef(cells[3,i],0);
    row4 := row4 + StrToFloatDef(cells[4,i],0);
    row5 := row5 + StrToFloatDef(cells[5,i],0);
    end;
  end;
  StringGrid1.Cells[6, 1] := FloatToStr(trunc(Col1/5*100+0.5)/100);
  StringGrid1.Cells[6, 2] := FloatToStr(trunc(Col2/5*100+0.5)/100);
  StringGrid1.Cells[6, 3] := FloatToStr(trunc(Col3/5*100+0.5)/100);
  StringGrid1.Cells[6, 4] := FloatToStr(trunc(Col4/5*100+0.5)/100);

  StringGrid1.Cells[1,5] := FloatToStr(trunc(row1/4*100+0.5)/100);
  StringGrid1.Cells[2,5] := FloatToStr(trunc(row2/4*100+0.5)/100);
  StringGrid1.Cells[3,5] := FloatToStr(trunc(row3/4*100+0.5)/100);
  StringGrid1.Cells[4,5] := FloatToStr(trunc(row4/4*100+0.5)/100);
  StringGrid1.Cells[5,5] := FloatToStr(trunc(row5/4*100+0.5)/100);

end;





end.
1  COMMENTS
  • Profile
    ㉳㉥ㅗ㉣ㅐ㉧ㅛ 2004.07.30 21:06



    StringGrid 이벤트에 SelectCell이란 것이 있습니다.

    CanSelect를 False로 하면 되여

    해당 Row를 정해주면 되것죠...


    그럼 즐코하세요