我在SelectCell事件中取stringgrid里的数据,取到的数据作为条件去另一个数据库查询资料。所以我在stringgrid的
MouseDown事件下写了PopupM1.Popup(mouse.CursorPos.X+15,mouse.CursorPos.Y+15);弹一小菜单,选择去向。我发现第一执行时。没有查询到东西,第2次就有了。
问题好像是:它先执行的MouseDown 完了以后才去执行SelectCell。。我想要他先执行SelectCell,在执行MouseDown 
怎么实现a?谢谢各位大哥哥了。

解决方案 »

  1.   

    加变量判断,比如Cando:Boolean; 初始值为False
    MouseDown 完毕后,Cando := True;SelectCell中写
    if not Cando then Exit;够恶心吧^_^
      

  2.   

    你可以不使用 OnMouseDown,使用OnMouseUp。
      

  3.   

    可以直接在MouseDown事件里面取单个元格的值啊
    procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      ACol, ARow :Integer;
      str :string;
    begin
      StringGrid1.MouseToCell(X, Y, ACol, ARow);
      if (ACol = -1) or (ARow = -1) then Exit;
      str := StringGrid1.Cells[ACol, ARow]
    end;