在DBgrid里面里的字段为number,name.
number  name
001     张三
002     李四
现想通过双击DBgrid任一条记录,在Edit里面就可显示name的值.
请教一下如何实现,谢谢.

解决方案 »

  1.   

    procedure TForm1.DBGrid1DblClick(Sender: TObject);      
            var
                no:string;
    begin
             if  ADOQuery2.Active then
                  begin
                    no:=DBGrid1.DataSource.DataSet.Fields[2].value;         //雙擊獲值
                    ADOQuery2.close;
                    ADOQuery2.SQL.clear;
                    //ADOQuery2.SQL.Add('select * from Tbl1 where id='''+no+'''');   //直接獲變量值
                    ADOQuery2.SQL.Add('select * from Tbl1 where id=:no');            //獲參查  
                    ADOQuery2.parameters.parambyname('no').value:=no;
    ADOQuery1.Prepared ;
                    ADOQuery2.open;
                  end;
    end;
      

  2.   

    //雙擊獲DBGrid1值。
    procedure TForm1.DBGrid1CellClick(Column: TColumn);
    begin
        showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString);
         with DBGrid1 do
        showmessage(format('row=%d',[SelectedIndex]));
        Edit.text:=DBGrid1.Datasource.Dataset.Fields[3].AsString;
    end;