发生OnSelectCell事件时,我需要判断上次选中的cell的值是否为空,为空的话,焦点重新回到上次选中的cell,如何实现?

解决方案 »

  1.   

    只能设置全局变量
    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      //..
      PRow := FRow;
      PCol := FCol;
      FRow := ARow;
      FCol := ACol;
    end;----------------
    沉沦中..........
      

  2.   

    这样子没有用阿,我可以算出上次选中cell的行和列,但是我无法在OnSelectCell事件中让焦点回置,SOS……
      

  3.   

    form1.StringGrid1.MouseToCell(0,0,acol,arow);
      form1.StringGrid1.Focused;
      

  4.   

    想选中的是上次焦点所在的Cell,这样写的话,不是选中的是这次了,我想可能不能在OnSelectCell中写的,不在知道在那个事件中写好?
      

  5.   

    全局变量记录上次选中的 FRow, FCol;procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      if trim(stringgrid1.Cells[FCol,FRow])='' then
      begin
        CanSelect:=false;
        StringGrid1.Row :=FRow;
        StringGrid1.Col :=FCol;
        StringGrid1.SetFocus;
      end
      else
      begin
        FRow:=ARow;
        FCol:=ACol;
      end;end;