如题.
在TQuery中有一个字段objfun, 希望录入时可以有一个下拉列表
增加 1
删除 2
编辑 3
保存 4
打印 5
查询 6
审核 7我应该怎样做?使得我选择"增加"或其它它存入数据库的是对应的数字?
在TQuery中有一个字段objfun, 希望录入时可以有一个下拉列表
增加 1
删除 2
编辑 3
保存 4
打印 5
查询 6
审核 7我应该怎样做?使得我选择"增加"或其它它存入数据库的是对应的数字?
如:
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是最好的,呵呵
1\是TQuery而且带有参数,而不是TTable,所以picklist和lookup可能不能用.(如果能用能详细点吗?)2\如果用DBComboBox1的话, 它能够集成到TDBGrid中吗? 否则光标无法控制!