如题!!!
解决方案 »
- delphi统计文件夹中各个excel文件的总行数
- delphi+Oracle:ORA-00942: 表或视图不存在??
- 打印机缺纸
- 有没有简单的方法交换DBGrid或者Query中两行记录的显示顺序
- delphi+MS SQL server 的数据库合并复制的实现???
- 气死人了!好不容易买到的“罗红霉素”居然被同事不由分说抢过就吃。我在东莞。
- 如何能实现dbgrid控件敲回车健光标自动移到下一列?
- 在SQL SERVER中的数据备份和恢复都只能处理数据库的数据,那存储过程要如何进行备份和恢复?
- 关于SPCOMM控件的安装问题
- 熟悉UML的朋友进来聊聊
- delphi中的绘图
- 帮忙了,给分了!!
那就在DBGrid连的AdoQuery或者Query的AfterScroll事件里动态添加好了。
先清空,然后添加指定内容。
使用dbcombobox控件到dbgrid
将数据库中数据加到dbcombobox中
或者直接在dbcombobox中加入应选择的项
在窗体上放一个DBComboBox,Visible为False;
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.