在DBGRID中输入某材料入库单据,输入材料代码后,怎么能同时在DBGRID中显示他的名称,保存时,只保存在入库单据的材料代码,

解决方案 »

  1.   

    用stringgrid吧,不要用DB控件直接操作数据
      

  2.   

    那就用新增字段吧!类型选LOOKUP。就行了。
      

  3.   

    如果用TClientDataSet連接, 自己創建個Lookup字段!關于Lookup字段的使用方法, 請看Delphi幫助
      

  4.   

    我也关注这个问题。
      用lookup感觉很慢。
      有没有更好的方式?
      

  5.   

    将要显示相关信息的字段名称设为空.
    BaseSet:相关信息数据集.
    procedure DBGrid1DrawColumnCell(Sender: TObject;const Rect: TRect; DataCol: Integer;   Column: TColumn;State: TGridDrawState);
    var
      GridSet:TAdoDataSet;
    begin
    if Column.FieldName<>'' then exit;
    GridSet:=TAdoDataSet((Sender as TDBGrid).DataSource.DataSet);
    if BaseSet.Locate('关联字段名',关联字段值,[loCaseInsensitive,loPartialKey]) then
      Width TDBGrid(Sender).Canvas do
      begin 
         FillRect(Rect);
         if Column.Title.Caption='显示的标题名名称' then
            TextOut(Rect.Left+2,Rect.Top+2,BaseSet.fieldbyName('关联字段名').AsString);  
      end;
    end;
      

  6.   

    关联字段值:=GridSet.FieldByName('关联字段名').asstring