在dbgrid表定义两个编辑字段,一个是manno(员工编号),一个是invoiceno(单据编号),点击manno字段,显示a窗体,点击invoiceno字段显示b窗体,请教高手,如何实现此项功能????

解决方案 »

  1.   

    在DBGRID的ONCELLCLICK中做代码就行了。
      

  2.   

    在 oncelclick 中写代码:
      procedure TFrom1.DBGrid1CellClick(Column: TColumn);
    begin
      inherited;
       if  Column.Index=1 then
       begin
           A:=TA.Create(Self);
           A.ShowModal;
           A.Free;
       end
       else
       begin
          B:=TB.Create(Self);
          B.ShowModal;
          B.Free;
       end;
    end;
      

  3.   

    if DBGrid1.SelectedField.FieldName='manno' then
    Forma.ShowModal;
    if DBGrid1.SelectedField.FieldName='invoicenono' then
    Formb.ShowModal;
      

  4.   

    下面代码请参考:
    procedure Tmainform.dbgrid1editbuttonclick(sender:Tobject);
    begin
      if dbgrid1.selectedfield=dmdata.table1 then
      with Ttable1.create(self) do
       try
         dmdata.table2.locate('IDNO',dmdata.table1IDNO.value,[]);
         if showmodal=mrok then
          with dmdata do
          begin
           if not (table1.state in [dsedit,dsinsert])  then
            table1.edit;
            table1IDNO.value:=table2.fields[0].value;
         end;
    finally;
    free;
    end
    else
     .......
      

  5.   

    if DBGrid1.SelectedField.FieldName='manno' then
    begin
     try
       Forma:=TForma.Create(Application);
      if Forma.ShowModal=mrOk then
         Forma.ShowModal;
     finally
        Forma:=nil;
        Forma.free;
     end;
    end;
    if DBGrid1.SelectedField.FieldName='invoicenono' then
    begin
     try
       Forma:=TForma.Create(Application);
       if Formb.ShowModal=mrOk then
          Formb.ShowModal;
      finally
         formb:=nil;
         formb.free
      end;
    end;
      

  6.   

    if DBGrid1.SelectedField.FieldName='manno' then
    begin
     try
       Forma:=TForma.Create(Application);
      if Forma.ShowModal=mrOk then
         Forma.ShowModal;
     finally
        Forma:=nil;
        Forma.free;
     end;
    end;
    if DBGrid1.SelectedField.FieldName='invoicenono' then
    begin
     try
       Forma:=TForma.Create(Application);
       if Formb.ShowModal=mrOk then
          Formb.ShowModal;
      finally
         formb:=nil;
         formb.free
      end;
    end;