unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, Grids, DBGrids, DB, DBTables;type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBComboBox1: TDBComboBox;
DBComboBox2: TDBComboBox;
DBComboBox3: TDBComboBox;
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure DBGrid1ColExit(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
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.Visible :=True;
end;
if (Field.FieldName = DBCombobox2.DataField) then
begin
DBCombobox2.Left :=Rect.Left + DBgrid1.Left;
DBCombobox2.Top := Rect.Top + DBgrid1.Top;
DBCombobox2.Width := Rect.Right - Rect.Left;
DBCombobox2.Visible :=True;
end; if (Field.FieldName = DBCombobox3.DataField) then
begin
DBCombobox3.Left :=Rect.Left + DBgrid1.Left;
DBCombobox3.Top := Rect.Top + DBgrid1.Top;
DBCombobox3.Width := Rect.Right - Rect.Left;
DBCombobox3.Visible :=True;
end;
end;
end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
if DBGrid1.SelectedField.FieldName = DBCombobox1.DataField then
begin
DBCombobox1.Visible := false;
end;
if DBGrid1.SelectedField.FieldName = DBCombobox2.DataField then
begin
DBCombobox2.Visible := false;
end;
if DBGrid1.SelectedField.FieldName = DBCombobox3.DataField then
begin
DBCombobox3.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; if (DBGrid1.SelectedField.FieldName = DBCombobox2.DataField ) then
begin
DBCombobox2.SetFocus;
SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
end; if (DBGrid1.SelectedField.FieldName = DBCombobox3.DataField ) then
begin
DBCombobox3.SetFocus;
SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
end;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, Grids, DBGrids, DB, DBTables;type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBComboBox1: TDBComboBox;
DBComboBox2: TDBComboBox;
DBComboBox3: TDBComboBox;
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure DBGrid1ColExit(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
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.Visible :=True;
end;
if (Field.FieldName = DBCombobox2.DataField) then
begin
DBCombobox2.Left :=Rect.Left + DBgrid1.Left;
DBCombobox2.Top := Rect.Top + DBgrid1.Top;
DBCombobox2.Width := Rect.Right - Rect.Left;
DBCombobox2.Visible :=True;
end; if (Field.FieldName = DBCombobox3.DataField) then
begin
DBCombobox3.Left :=Rect.Left + DBgrid1.Left;
DBCombobox3.Top := Rect.Top + DBgrid1.Top;
DBCombobox3.Width := Rect.Right - Rect.Left;
DBCombobox3.Visible :=True;
end;
end;
end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
if DBGrid1.SelectedField.FieldName = DBCombobox1.DataField then
begin
DBCombobox1.Visible := false;
end;
if DBGrid1.SelectedField.FieldName = DBCombobox2.DataField then
begin
DBCombobox2.Visible := false;
end;
if DBGrid1.SelectedField.FieldName = DBCombobox3.DataField then
begin
DBCombobox3.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; if (DBGrid1.SelectedField.FieldName = DBCombobox2.DataField ) then
begin
DBCombobox2.SetFocus;
SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
end; if (DBGrid1.SelectedField.FieldName = DBCombobox3.DataField ) then
begin
DBCombobox3.SetFocus;
SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
end;
end;
end;end.
解决方案 »
- 双人象棋对战程序源代码下载
- 求Delphi 5.x 分布式多层应用电子商务篇的配套光盘原码
- ActiveSkin V4.3是否支持delphi7
- 急:delphi6 自带的f1book 怎么合并单元格
- DELPHI6中的INDY组件中的TIdAntiFreeze,TIdMessage 在DELPHI7是放在哪里?或相当哪个控件?
- 在listview中,如何能让滚动到selected的items上呀????
- 如何用ADOX创建ACCESS数据表?
- 如何实现用shift键多选?
- 程序运行时不可见(包括任务栏和托盘)应该怎么办?
- idhttp post 方法疑问,懂者请进解疑~~~~
- 可不可以在提交按钮的代码里加判断的条件,紧急!!!
- 调试Socket通讯程序报错!下午在线!!
DBGrid里点鼠标右键,选“Columns editor...”,鼠标右键,选“Add All Fields”加入所有字段。点你要加ComboBox的字段,在左边的Object Inspector中找到PickList属性。填入你想出现在ComboBox中的项目,就象填普通ComboBox的items属性一样。程序运行后,在设置了pickList属性的字段上双击鼠标,就会出现一个ComboBox
begin
DBGrid1.Columns[0].PickList.Text := 'line1'#13#10'line2'#13#10;
end;
颜色也可以改变,呵呵,//可以改变DBGrid里的颜色的,不同的记录有不同的颜色
------------------------------------------------------------
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.
-----------------------------------------------------