100分,在线等 DBGrideh下拉框如何设置. DBGrideh下拉框如何设置,下拉内容动态显示某个字段的所有值,谢谢啊 pickList,keyList 是手动输入的啊。我是新手,不明白怎么设置.设置lookup字段详细一点。不太懂delphi,时间又急。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls, DBCtrls;type TForm1 = class(TForm) DBGrid1: TDBGrid; ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DataSource1: TDataSource; DBComboBox1: TDBComboBox; SaveDialog1: TSaveDialog; procedure DBGrid1TitleClick(Column: TColumn); procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); procedure DBGrid1KeyPress(Sender: TObject; var Key: Char); procedure DBGrid1ColExit(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1TitleClick(Column: TColumn);var x: Integer; TheField: string;begin x := column.Index; TheField := self.ADOQuery1.Fields[x].FieldName; self.ADOQuery1.Close; self.ADOQuery1.SQL.Clear; self.ADOQuery1.SQL.Text := 'select * from Tb1 order by '+ TheField; self.ADOQuery1.Open;end;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 self.DBComboBox1.Left := Rect.Left + self.DBGrid1.Left; self.DBComboBox1.Top := Rect.top + self.DBGrid1.Top; self.DBComboBox1.Width := Rect.Right - Rect.Left; DBComboBox1.Height := Rect.Bottom - Rect.Top; self.DBComboBox1.Visible := True; end; end;end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);beginif (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; if key = #13 then //enter 替代Tab if not(ActiveControl is TDBGrid) then begin key := #0; perform(WM_NEXTDLGCTL,0,0); end else if (ActiveControl is TDbGrid) then with TDBGrid(ActiveControl) do if selectedindex <(fieldcount - 1) then selectedindex := selectedindex + 1 else selectedindex := 0;end;procedure TForm1.DBGrid1ColExit(Sender: TObject);begin If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then begin DBComboBox1.Visible := false; end;end;end. 卡庙厉害.呵呵其实 PickList,keyList 对于静态数据,在界面加载时动态加载后效率是挺高的. indy控件问题 DELPHI5 里面的 DESKTOP DADABASE 支持表间的关系吗? 看看这个调用word程序的代码,在你们机子上能用嘛 《请教》如何将一个目录下的所有文件的文件名载入memo DBGrid的显示问题! 我要打印下面样式的表单,怎么实现,在线急等! 小问题,却很急 Delphi下使用SQL DMO 开发程序时,其中的图画是如何搞出来的? 如何去掉窗口的caption栏显示?我就是不想要上面的蓝条!!!!还有delphi打开project时显示找不到其res文件,是怎么回事? Delphi传递数组到WCF后变为Null 请问如何像QQ那样的好友的HINT提示?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls, DBCtrls;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBComboBox1: TDBComboBox;
SaveDialog1: TSaveDialog;
procedure DBGrid1TitleClick(Column: TColumn);
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1ColExit(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
x: Integer;
TheField: string;
begin
x := column.Index;
TheField := self.ADOQuery1.Fields[x].FieldName;
self.ADOQuery1.Close;
self.ADOQuery1.SQL.Clear;
self.ADOQuery1.SQL.Text := 'select * from Tb1 order by '+ TheField;
self.ADOQuery1.Open;
end;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
self.DBComboBox1.Left := Rect.Left + self.DBGrid1.Left;
self.DBComboBox1.Top := Rect.top + self.DBGrid1.Top;
self.DBComboBox1.Width := Rect.Right - Rect.Left;
DBComboBox1.Height := Rect.Bottom - Rect.Top;
self.DBComboBox1.Visible := True;
end;
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; if key = #13 then //enter 替代Tab
if not(ActiveControl is TDBGrid) then
begin
key := #0;
perform(WM_NEXTDLGCTL,0,0);
end
else
if (ActiveControl is TDbGrid) then
with TDBGrid(ActiveControl) do
if selectedindex <(fieldcount - 1) then
selectedindex := selectedindex + 1
else
selectedindex := 0;end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
begin
DBComboBox1.Visible := false;
end;
end;end.
其实 PickList,keyList 对于静态数据,在界面加载时动态加载后效率是挺高的.