(跪求)dbgrid中加入有下拉框的控件,如combobox等
时间:2009-04-14
来源:互联网
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; {这里会报错,弹出not visible,不可见,不能获得焦点}
SendMessage(DBComboBox1.Handle, WM_Char, word(Key), 0);
end;
end;
end;
请高手能够给我指点,我理解的是在在我的keypress时根本没有执行绘制表格单元,在setfocus之前需要重画?恳请大哥大姐帮帮迷途的小弟!
作者: jonathan_worj 发布时间: 2009-04-14
作者: rouqing 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
Field: TField; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (Field.FieldName = DBComboBox1.DataField ) then
begin
DBComboBox1.Left := Rect.Left + DBGrid2.Left;
DBComboBox1.Top := Rect.Top + DBGrid2.top;
DBComboBox1.Width := Rect.Right - Rect.Left;
DBComboBox1.Height := Rect.Bottom - Rect.Top;
DBComboBox1.Visible := True;
SendMessage(DBComboBox1.Handle, CB_SHOWDROPDOWN , Integer(True), 0);//在这里加上这句
end;
end;
end;
把procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);事件中的代码去掉。
作者: lovelymelon 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
Delphi(Pascal) code
self.ADOQuery5.Close; self.ADOQuery5.Connection:=self.ADOConnection2; Self.ADOQuery5.SQL.Clear; Self.ADOQuery5.SQL.Add('select distinct bianhao from Tzhk_czp'); self.ADOQuery5.Open; while not Self.ADOQuery5.Eof do begin sql:=Self.ADOQuery5.FieldByname('bianhao').AsString; self.DBComboBox1.Items.Add(sql); self.ADOQuery5.Next; end;
作者: lovelymelon 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
作者: lovelymelon 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
作者: lovelymelon 发布时间: 2009-04-14
作者: jonathan_worj 发布时间: 2009-04-14
onchange事件中
procedure TForm1.ComboBox1Change(Sender: TObject);
var p:string;
begin
if(combobox1.text<>'') then begin//为空的时候不触发 不然会再下拉框中填充所有数据
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('Select * FROM tb_company where CompanyName like :p');
Parameters.ParamByName('p').Value:='%'+trim(combobox1.text)+'%';//查找匹配的数据
open;
end;
combobox1.items.text:='';
ComboBox1.SelStart:= Length(ComboBox1.Text);//确保光标会在后面 否则会自动跳到输入数据前面
while not adoquery1.Eof do
begin
ComboBox1.Items.Add(adoquery1.Fieldbyname('CompanyName').AsString);//下拉框中把匹配的数据绑定
adoquery1.Next;
end;
end;
end;
你参考下
作者: a381391536 发布时间: 2011-08-10
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28