Q&A

  • StringGrid의 cell에 숫자입력할때 포맷지정하는 방법?
안녕하세요



StringGrid에서 숫자를 입력하는데 콤마나 소숫점등의 포맷을 표현하고 싶은데



어떤 이벤트에서 어떤 코딩을 해줘야 할지 잘 모르겠습니다



도와주세요.





1  COMMENTS
  • Profile
    홍성락 2001.07.25 19:32
    써비 wrote:

    > 안녕하세요

    >

    > StringGrid에서 숫자를 입력하는데 콤마나 소숫점등의 포맷을 표현하고 싶은데

    >

    > 어떤 이벤트에서 어떤 코딩을 해줘야 할지 잘 모르겠습니다

    >

    > 도와주세요.

    ///////////////////////////////////////////////////////////////////////////

    좀 정리가안되서 참조만하세요

    procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,

    ARow: Integer; const Value: String);

    var

    i, count : integer;

    Str_Temp, Str_Temp2, Str_Temp3, Str_sign, Str_decimal : string;

    begin

    with TStringGrid(Sender) do begin

    if ACol = 1 then begin //원하는 셀

    if Value = '' then exit;

    Str_Temp := Value;

    //부호,소숫점뒤 걸러내기

    Str_sign := '';

    if Str_Temp[1] = '-' then begin

    Str_sign := '-';

    Str_Temp := copy(Str_Temp,2, length(Str_Temp));

    end;

    Str_decimal := '';

    if pos('.',Str_Temp)>0 then begin

    Str_decimal := copy(Str_Temp,pos('.',Str_Temp), length(Str_Temp));

    Str_Temp := copy(Str_Temp,1,pos('.',Str_Temp)-1);

    end;



    Str_Temp := StringReplace(Str_Temp, ',', '', [rfReplaceAll]);

    if length(Str_Temp)>3 then begin

    count := (length(Str_Temp)-1) div 3;

    for i := count downto 1 do begin

    Str_Temp2 := copy(Str_Temp,1,length(Str_Temp)-3*i);

    Str_Temp3 := copy(Str_Temp,length(Str_Temp)-3*i+1, length(Str_Temp));

    Str_Temp := Str_Temp2 +','+Str_Temp3;

    end;

    cells[Acol, Arow] := Str_sign+Str_Temp+Str_decimal;

    EditorMode := True;

    end;

    end;

    end;

    end;



    procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);

    begin

    if TStringGrid(Sender).Col = 1 then //원하는 셀

    if not(Key in ['0'..'9','.','-',#8]) then Key := #0;

    end;