S
seastar_cui
Unregistered / Unconfirmed
GUEST, unregistred user!
unit umember_chaxun1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, ComCtrls, ImgList;
type
Tmember_chaxun1 = class(TForm)
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ComboBox1: TComboBox;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Button1: TButton;
ImageList1: TImageList;
Edit1: TEdit;
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1ColExit(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
member_chaxun1: Tmember_chaxun1;
implementation
{$R *.dfm}
uses main,umember;
procedure Tmember_chaxun1.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
dbgrid1.Columns[0].Title.caption:='序号';
dbgrid1.Columns[0].Title.alignment:=tacenter;
dbgrid1.Columns[0].Width :=30;
dbgrid1.Columns[1].Title.caption:='项目';
dbgrid1.Columns[1].Title.alignment:=tacenter;
dbgrid1.Columns[2].Title.caption:='关系';
dbgrid1.Columns[2].Title.alignment:=tacenter;
dbgrid1.Columns[3].Title.caption:='查询值';
dbgrid1.Columns[3].Title.alignment:=tacenter;
dbgrid1.Columns[3].Width :=150;
dbgrid1.Columns[4].Title.caption:='逻辑';
dbgrid1.Columns[4].Title.alignment:=tacenter;
if (gdFocused in State) then
begin
if dbgrid1.SelectedField.Index =2 then //2为关系字段列columns[2];
begin
ComboBox1.Left := Rect.Left + DBGrid1.Left;
ComboBox1.Top := Rect.Top + DBGrid1.top;
ComboBox1.Width := Rect.Right - Rect.Left;
ComboBox1.Height := Rect.Bottom - Rect.Top;
ComboBox1.Visible := True;
combobox1.SetFocus ;
combobox1.Height :=400;
end;
end;
end;
procedure Tmember_chaxun1.FormCreate(Sender: TObject);
begin
combobox1.Parent :=dbgrid1;
adoquery1.Active :=true;
adoquery1.LockType := ltBatchOptimistic;
end;
procedure Tmember_chaxun1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> chr(9)) then
begin
if dbgrid1.SelectedField.Index =2 then
begin
ComboBox1.SetFocus;
SendMessage(ComboBox1.Handle,WM_Char,word(Key),0);
end;
end;
end; //这段代码好像没有起什么作用。
procedure Tmember_chaxun1.DBGrid1ColExit(Sender: TObject);
begin
combobox1.Visible :=false;
end;
procedure Tmember_chaxun1.DBGrid1CellClick(Column: TColumn);
begin
if dbgrid1.SelectedField.Index <>2 then
begin
combobox1.Visible :=false;
end;
end;
procedure Tmember_chaxun1.Button1Click(Sender: TObject);
begin
adoquery1.UpdateBatch();
end;
procedure Tmember_chaxun1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
adoquery1.CancelBatch;
adoquery1.Active :=false;
member_chaxun1.Release ;
member_chaxun1:=nil;
end;
procedure Tmember_chaxun1.FormShow(Sender: TObject);
begin
dbgrid1.Columns.State :=csdefault;
end;
end.
以上这个窗体的全部代码,问题是Combobox1里选定的值不能到DBgrid1里,在Combobox1的
OnSelect事件里,让COMBOBOX1里的值到edit1中去,也做不到,另外再请问一下dbgrid的ADOQUERY1,在什么情况下,可以在DBGRID1里自由输入?
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB, ComCtrls, ImgList;
type
Tmember_chaxun1 = class(TForm)
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ComboBox1: TComboBox;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Button1: TButton;
ImageList1: TImageList;
Edit1: TEdit;
procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1ColExit(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
member_chaxun1: Tmember_chaxun1;
implementation
{$R *.dfm}
uses main,umember;
procedure Tmember_chaxun1.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
dbgrid1.Columns[0].Title.caption:='序号';
dbgrid1.Columns[0].Title.alignment:=tacenter;
dbgrid1.Columns[0].Width :=30;
dbgrid1.Columns[1].Title.caption:='项目';
dbgrid1.Columns[1].Title.alignment:=tacenter;
dbgrid1.Columns[2].Title.caption:='关系';
dbgrid1.Columns[2].Title.alignment:=tacenter;
dbgrid1.Columns[3].Title.caption:='查询值';
dbgrid1.Columns[3].Title.alignment:=tacenter;
dbgrid1.Columns[3].Width :=150;
dbgrid1.Columns[4].Title.caption:='逻辑';
dbgrid1.Columns[4].Title.alignment:=tacenter;
if (gdFocused in State) then
begin
if dbgrid1.SelectedField.Index =2 then //2为关系字段列columns[2];
begin
ComboBox1.Left := Rect.Left + DBGrid1.Left;
ComboBox1.Top := Rect.Top + DBGrid1.top;
ComboBox1.Width := Rect.Right - Rect.Left;
ComboBox1.Height := Rect.Bottom - Rect.Top;
ComboBox1.Visible := True;
combobox1.SetFocus ;
combobox1.Height :=400;
end;
end;
end;
procedure Tmember_chaxun1.FormCreate(Sender: TObject);
begin
combobox1.Parent :=dbgrid1;
adoquery1.Active :=true;
adoquery1.LockType := ltBatchOptimistic;
end;
procedure Tmember_chaxun1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> chr(9)) then
begin
if dbgrid1.SelectedField.Index =2 then
begin
ComboBox1.SetFocus;
SendMessage(ComboBox1.Handle,WM_Char,word(Key),0);
end;
end;
end; //这段代码好像没有起什么作用。
procedure Tmember_chaxun1.DBGrid1ColExit(Sender: TObject);
begin
combobox1.Visible :=false;
end;
procedure Tmember_chaxun1.DBGrid1CellClick(Column: TColumn);
begin
if dbgrid1.SelectedField.Index <>2 then
begin
combobox1.Visible :=false;
end;
end;
procedure Tmember_chaxun1.Button1Click(Sender: TObject);
begin
adoquery1.UpdateBatch();
end;
procedure Tmember_chaxun1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
adoquery1.CancelBatch;
adoquery1.Active :=false;
member_chaxun1.Release ;
member_chaxun1:=nil;
end;
procedure Tmember_chaxun1.FormShow(Sender: TObject);
begin
dbgrid1.Columns.State :=csdefault;
end;
end.
以上这个窗体的全部代码,问题是Combobox1里选定的值不能到DBgrid1里,在Combobox1的
OnSelect事件里,让COMBOBOX1里的值到edit1中去,也做不到,另外再请问一下dbgrid的ADOQUERY1,在什么情况下,可以在DBGRID1里自由输入?