怎样在dbgrid中双击某行将这行所对应的数据字段的值复制给相应的edit,如有5个字段,其对应的edit分别是edit1,edit2,edit3...edit5;

解决方案 »

  1.   

    在双击事件中写:
    edit1.text:=query1.fieldbyname('field').asstring;
      

  2.   

    procedure TForm1.DBGrid1DblClick(Sender: TObject);
    begin
    edit1.text:=query1.fieldbyname('field').asstring;
    end;
      

  3.   

    针对小飞侠的补充一下:
     case dbgrid.selectedfield.index of 
       0: begin
           edit1.text:=table.field[0].asstring;
          end;
       1: ;
       ..
       n: ;
      end;//end of case
      其中的n为字段个数减1.
      

  4.   

    procedure TForm1.DBGrid1DblClick(Sender: TObject);
    begin
     
     case dbgrid.selectedfield.index of 
       0: begin
           edit1.text:=table.fieldbyname('name').asstring;
          end;
       1: ;
       ..
       n: ;
      end;//end of case
      其中的n为字段个数减1.
    end;
      

  5.   

    edit1.text:=query1.fieldbyname('field').asstring;
      

  6.   

    我想你可以这样去理解,那就是当你使用dbgrid时如果要操作你都是对它所对用的dagasource或者也可以是直接的dataset来进行操作。因为你在dbgrid中的行的移动也会使数据库的cursor移动。你直接存取数据库中的当然记录就可以了。