스트링그리드에 자료를 집어넣구여....
___________________________________
농구화 테니스화 축구화
총판매액 20000 30000 50000
판매빈도 20 30 50
여기안에 숫자들의 표현형식을 판매액은 30,000 이런식으로 하고요
빈도는 20%이케할라고 하는데.....
직접셀에다 %등은 추가시킬수두 있는데염....
이상태에서 가로합계버튼을 누르면 합계가 구해지게할려구 하거든요....
그럴려면....셀자체에 %같은게 있으면 정수로 변환할수 없잖아요...
그냥 형식으로 무슨 이런표현넣어주는거 있나요?
아님..... copy나 pos같은거로.....%나 ,같은거 걸러내구 해야하나요....
제가 말할려구하는게 이해되셨는지모르겟군염...^^
> 스트링그리드에 자료를 집어넣구여....
> ___________________________________
> 농구화 테니스화 축구화
> 총판매액 20000 30000 50000
> 판매빈도 20 30 50
>
> 여기안에 숫자들의 표현형식을 판매액은 30,000 이런식으로 하고요
> 빈도는 20%이케할라고 하는데.....
> 직접셀에다 %등은 추가시킬수두 있는데염....
> 이상태에서 가로합계버튼을 누르면 합계가 구해지게할려구 하거든요....
> 그럴려면....셀자체에 %같은게 있으면 정수로 변환할수 없잖아요...
> 그냥 형식으로 무슨 이런표현넣어주는거 있나요?
> 아님..... copy나 pos같은거로.....%나 ,같은거 걸러내구 해야하나요....
> 제가 말할려구하는게 이해되셨는지모르겟군염...^^
//////////////////////////////////////////////////////////////
1.우선 셀형식별 표현은 전번에도 편한것이있어 권해드렸었거든요
function gfSetCellCfg(psGrid : TStringGrid; pRect : TRect;
piCol, piRow, pialign : Integer; pTxtColor, pCellColor: Tcolor; psNum2 : string): integer;
var
OldColor : TColor;
Oldalign : word;
begin
// Result := 0;
with psGrid do begin
Oldalign := settextalign(Canvas.Handle, pialign);
Canvas.Font := psGrid.Font;
Canvas.Font.Color := pTxtColor;
OldColor := Canvas.Brush.Color;
Canvas.Brush.Color := pCellColor;
case pialign of
TA_LEFT :
Canvas.TextRect(pRect,
pRect.left+10,
(pRect.Top+pRect.Bottom-psGrid.Font.Size-2) div 2,
cells[piCol,piRow]);
TA_RIGHT :
Canvas.TextRect(pRect,
pRect.right-10,
(pRect.Top+pRect.Bottom-psGrid.Font.Size-2) div 2,
gfGetCommaStr(cells[piCol,piRow])+psNum2);
TA_CENTER :
Canvas.TextRect(pRect,
(pRect.left+pRect.right) div 2,
(pRect.Top+pRect.Bottom-psGrid.Font.Size-2) div 2,
cells[piCol,piRow]);
end;
Canvas.Brush.Color := OldColor;
settextalign(Canvas.Handle, Oldalign);
end;
Result := 1;
end;
function gfGetCommaStr(psNum : string) : string;
var
sFmt : string;
i : integer;
begin
sFmt := '#,##0';
if psNum <> '' then begin
if pos('.', psNum) > 0 then begin
sFmt := sFmt+'.';
for i := 1 to (length(psNum) - pos('.', psNum) ) do
sFmt := sFmt+'0';
end;
Result := FormatFloat(sFmt, StrToFloat(psNum));
end else
Result := '';
end;
-----------------------------------------------------------------------------
2.스트링그리드에서의 이벤트처리는 위 예제처럼 첫줄은 중앙문자정렬, 두번째는 숫자로 콤마표현으로 오른쪽정렬입니다
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ARow = 0)or(ACol = 0) then
gfSetCellCfg(StringGrid1, Rect, ACol, ARow, TA_CENTER, clBlack, clWhite, '')
else if (ARow = 1)and(ACol <> 0) then
gfSetCellCfg(StringGrid1, Rect, ACol, ARow, TA_RIGHT, clBlack, clWhite, '')
else if (ARow = 2)and(ACol <> 0) then
gfSetCellCfg(StringGrid1, Rect, ACol, ARow, TA_RIGHT, clBlack, clWhite, '%');
end;
------------------------------------------------------------------------
3.계산하실때는 셀개수만큼 루프를돌려 합하시고요 그때 셀에서 구한 문자에서
%와 ,를 빼시려면 StringReplace(Sou_STR, '%', '', [rfReplaceAll])함수를 쓰시면됩니다.
위에것은 응용해서 쓰시면 될겁니다.