如何实现双击stringgrid一行打开一个新的窗体,并在新窗体内显示该记录的详细信息。

解决方案 »

  1.   

    procedure TForm1.StringGrid1DblClick(Sender: TObject);
    var
      r:Integer;
    begin
      r := StringGrid1.Row ;
      ShowMessage(StringGrid1.Cells[0,r] );
    end;r是行,StringGrid1.Row是当前选中的行数,StringGrid1.Cells[x,y]是某个单元格的数据,x、y分别是行数和列数。
      

  2.   

    procedure TForm1.StringGrid1Click(Sender: TObject);
    begin
      with form2 do
      begin
        Edit1.Text := StringGrid1.Rows[StringGrid1.Row].Strings[1];
        Show;
      end;
    end;procedure TForm1.MCFormCreate(Sender: TObject);
    begin
    StringGrid1.Cells[1,1] := 'test'
    end;
      

  3.   

    建个一新的窗体,里面放一个Memo,然后uses到StringGrid的窗体中procedure TForm1.StringGrid1DblClick(Sender: TObject);
    begin
       form2.Memo1.Lines.Assign(StringGrid1.Rows[StringGrid1.Row]);
       form2.Show;
    end;
      

  4.   

    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      with TForm2.Create(Owner,StringGrid1.Cells[ACol,ARow]) do
      begin
        showmodal;
        Destroy;
      end;
    end;
    ///
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
        Edit1: TEdit;
      private
        { Private declarations }
      public
        Constructor Create( AOwner:TComponent;s:string );overload;
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.dfm}{ TForm2 }{ TForm2 }constructor TForm2.Create(AOwner: TComponent; s: string);
    begin
      inherited Create( AOwner );
      self.Edit1.Text:=s;
    end;end.