一个stringgrid中有三列,分别为   单价、数量、总金额   要求 在输入单价、数量后,总金额列自动显示出总金额,用什么事件?

解决方案 »

  1.   


    procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
      ARow: Integer; const Value: String);
    var
      total:Currency;
    begin
      total := StrToFloatDef(StringGrid1.Cells[1,ARow],0)*StrToFloatDef(StringGrid1.Cells[2,ARow],0);
      StringGrid1.Cells[3,ARow] := FloatToStr(total);
    end;
      

  2.   

    可以设置一个属性,在写属性事件中,加一句stringgrid1.refresh;
      

  3.   

    加二EditCellEditor控件,双击stringgrid单价、数量两列分别指定Editor到这两个控件,在EditCellEditor控件的AllowEndEditEvent事件中,if key=13 then .....(回车表示输入结束,就可以做计算处理),
    可以在stringgrid的OnSelectCell事件中获取正在输入的CELL的行号列号
      

  4.   

    procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
      ARow: Integer; const Value: String);
    var
      total:Currency;
    begin
      total := StrToFloatDef(StringGrid1.Cells[1,ARow],0)*StrToFloatDef(StringGrid1.Cells[2,ARow],0);
      StringGrid1.Cells[3,ARow] := FloatToStr(total);
    end;