DBGridEh中 如何使某个字段出现下拉选择框
注意:下拉框的内容‘为另外一个数据表的内容,可以包括好几个字段’,
就象EHLIB中自带的DEMO1的效果。请各位大虾门尽量写多一点,我看了DEMO1的相关设置,试了一下没弄出来,不知道哪里错了,所以希望各位写清楚些,谢过先!

解决方案 »

  1.   

    listsource填上
    lookupdisplayfields字段用分号间隔开
    goog luck!
      

  2.   

    就填这两个吗?
    好象不行啊,DEMO1设的不是这样的
    有谁清楚啊
      

  3.   

    是这样的:
    先创建一个次DataSet,就是要显示下拉的,其中要包括与主DataSet相关联字段;
    再在主DataSet建一LookUp字段,比如snamel,用以替换原sname显示;而此snamel是显示在DBGridEh中的;主DataSet与次DataSet是通过sname连接;
    然后就可以在DBGridEh字段的ListDisplayFields输入你要显示的字段,用;隔开
      

  4.   

    listsource填上
    lookupdisplayfields字段用分号间隔开
    就可以啦
      

  5.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      //ShowMessage('in');
      if (gdFocused in State) then
      begin    if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField ) then
        begin      DBComboBox1.Left := Rect.Left + DBGrid1.Left;
          DBComboBox1.Top := Rect.Top + DBGrid1.top;
          DBComboBox1.Width := Rect.Right - Rect.Left;
          DBComboBox1.Height := Rect.Bottom - Rect.Top;
          DBComboBox1.Visible := True;
        end;
      end;
    end;procedure TForm1.DBGrid1ColEnter(Sender: TObject);
    begin
    If DBGrid1.SelectedField.FieldName <> DBComboBox1.DataField then
    begin
    DBComboBox1.Visible := false;
    end;end;
      

  6.   

    //在DBGGrid里面插入Combobox
    procedure Tsubject1.DBGrid2ColExit(Sender: TObject);
    begin
     if DBGrid1.SelectedField.FieldName = DBCombobox1.DataField then
        DBCombobox1.Visible := false;
    end;procedure Tsubject1.DBGrid2DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
         if (gdFocused in State) then
      begin
         if (column.FieldName = DBCombobox1.DataField) then
         begin
           DBCombobox1.Left :=Rect.Left + DBgrid1.Left+3;
           DBCombobox1.Top := Rect.Top + DBgrid1.Top;
           DBCombobox1.Width := Rect.Right - Rect.Left+1;
           DBCombobox1.Visible :=True;
         end;
      end;
    end;