如何获取所选单元格的总和值或范围stringgrid
?请注意,有时这些单元格包含字符串值!
我尝试过GridCoord
,但效果不佳,因为有时会有“隐藏列”。
procedure TMainShowForm.StgSelectionChanged(Sender: TObject; ALeft, ATop,
ARight, ABottom: Integer);
var
i: Integer;
gc: TGridCoord;
sum:double;
begin
for i := 1 to stg.SelectedCellsCount do
begin
gc := stg.SelectedCell[i - 1];
sum:=sum+stg.floats[(gc.X),(gc.Y)];
end;
AdvOfficeStatusBar1.Panels[0].Text:='Sum = '+ formatfloat('#,##0.',sum);
AdvOfficeStatusBar1.Panels[1].Text:='Count = '+ inttostr(stg.SelectedCellsCount);
end;