![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
всем доброго времени суток.. помогите написать пожалуйста код.. нужно чтобы в ячейках стринггрида считались данные во всей таблице одновременно и выводило результат в некое "итого". которое находится под каждым считаемым столбцом грубо говоря.. я написал код, который может считать только по одному столбцу
Код:
var
d : array[0..300] of real;
i,j : integer;
d[1] := 0;
for i:=6 to StringGrid1.RowCount-10 do d[1] := d[1] + StrToFloat(StringGrid1.Cells[2,i]);
StringGrid1.Cells[2,30]:= FloatToStr(d[1]);всего в нем 262 столбца.. как правильно сделать цикл для всего стринггрида? |
|
#2
|
|||
|
|||
|
Что-то типа того:
Код:
procedure TForm1.Button2Click(Sender: TObject);
var
i,j:Cardinal;
Sum:real;
begin
for i:=0 to StringGrid1.ColCount-1 do
begin
for j:=0 to StringGrid1.RowCount-2 do
begin
StringGrid1.Cells[i,j]:=InputBox('','','');
end;
end;
for i:=0 to StringGrid1.ColCount-1 do
begin
Sum:=0;
for j:=0 to StringGrid1.RowCount-2 do
begin
Sum:=Sum+StrToFloat(StringGrid1.Cells[i,j]);
end;
StringGrid1.Cells[i,StringGrid1.RowCount-1]:=FloatToStr(Sum);
end;
end; |
|
#3
|
||||
|
||||
|
Код:
For i:= 0 to StringGrid1.ColCount - 1 do
For j:= 0 to StringGrid1.RowCount - 1 do |
|
#4
|
||||
|
||||
|
Код:
var
d : array[0..300] of real;
i,j : integer;
d[1] := 0;
for j := 0 to StringGrid1.ColCount - 1 do
for i:=6 to StringGrid1.RowCount-10 do d[1] := d[1] + StrToFloat(StringGrid1.Cells[2,i]);
StringGrid1.Cells[2,30]:= FloatToStr(d[1]); |
|
#5
|
|||
|
|||
|
этот кусочек кода не пригодился:
Код:
for i:=0 to StringGrid1.ColCount-1 do
begin
for j:=0 to StringGrid1.RowCount-2 do
begin
StringGrid1.Cells[i,j]:=InputBox('','','');
end;
end;Вы мне очень помогли!! спасибо большое!!! |
|
#6
|
||||
|
||||
|
Вот так элегантнее, т.к. подсчет идет налету:
Код:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
Var Row: Integer;
Summ: Extended;
Table: TStringGrid;
begin
Table := TStringGrid(Sender);
if ACol = Table.FixedCols - 1 then Exit;
Summ := 0;
for Row := Table.FixedRows to Table.RowCount - 2
do Summ := Summ + StrToFloatDef(Table.Cells[ACol,Row], 0);
if Table.Cells[ACol,Table.RowCount - 1] <> FloatToStr(Summ)
then Table.Cells[ACol,Table.RowCount - 1] := FloatToStr(Summ);
end; |