如题.
在TQuery中有一个字段objfun, 希望录入时可以有一个下拉列表
增加   1
删除   2 
编辑   3
保存   4
打印   5
查询   6
审核   7我应该怎样做?使得我选择"增加"或其它它存入数据库的是对应的数字?

解决方案 »

  1.   

    可以设置一个lookup字段,同时采用ehlib控件可轻松实现!
      

  2.   

    用DBLOOKUPCOMBOBOX结合lookup字段就能够实现,显示的为lookup字段,而实际存储的字段内容就是对应的数字了,当然这样你需要一个代码对应的表。
      

  3.   

    www.nxrs.net/bbs上有这样的贴子,你可以参考;
    如:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DBCtrls, DB, DBTables, Grids, DBGrids;type
      TForm1 = class(TForm)
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        Table1: TTable;
        DBComboBox1: TDBComboBox;
        procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
          Field: TField; State: TGridDrawState);
        procedure DBGrid1ColExit(Sender: TObject);
        procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
        procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
          DataCol: Integer; Column: TColumn; State: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
    if (gdFocused in State) then
       begin
        if ( Field.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.DBGrid1ColExit(Sender: TObject);
    begin
      If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
      begin
        DBComboBox1.Visible := false;
      end;           
    end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (key <> chr(9)) then
      begin
        if (DBGrid1.SelectedField.FieldName=DBComboBox1.DataField) then
        begin
          DBComboBox1.SetFocus;
          SendMessage(DBComboBox1.Handle, WM_Char, word(Key), 0);
        end;
      end;
    end;procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if Table1.FieldByName('SIZE').AsInteger = 2 then
      begin
        DBGrid1.Canvas.Font.Color:=clred;
        DBGrid1.Canvas.Brush.color:=clyellow;
      end else
      begin
        DBGrid1.Canvas.Font.Color:=clblue;
        DBGrid1.Canvas.Brush.color:=clBtnFace;
      end;
      DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
    end;end.
    卖个乖
    -------------------------------------------------------------
    寻寻寻,寻斑竹小小在线
    如果您觉的您对Delphi 感兴趣或是很想学的更好些或者是对Delphi 有更深的认识,我们可以一起交流;
    呵呵
    www.nxrs.net/bbs
    谢谢,别抛砖
    -----------------------------------------------------------------
    声明:在那儿交流都一样的,我现在还是认为Csdn是最好的,呵呵
      

  4.   

    编辑DBGRID列,在列objfun的属性里面找到picklist在里面添加就行。
      

  5.   

    首先要说的:
    1\是TQuery而且带有参数,而不是TTable,所以picklist和lookup可能不能用.(如果能用能详细点吗?)2\如果用DBComboBox1的话, 它能够集成到TDBGrid中吗? 否则光标无法控制!
      

  6.   

    已经解决.给分用得是picklist和ongettext,onsettext!