求助高手在dbgrid中加入可视控件问题

liuzhengstar 2003-08-20 09:36:16
源代码为:
procedure Tzccs.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 Tzccs.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName
= DBComboBox1.DataField then
begin
DBComboBox1.Visible := false;
end;

end;

procedure Tzccs.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 + 25;
DBComboBox1.Width := Rect.Right - Rect.Left;
DBComboBox1.Height := Rect.Bottom - Rect.Top;
DBComboBox1.Visible := True;
end;
end;

end;

在dbgrid的columns editor中使用add all fields之后,可视控件就无法出现在dbgrid中.环境为win98 delphi7.0
...全文
35 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
prosectinfo 2003-08-20
  • 打赏
  • 举报
回复
我这样用的,把DrawDataCell事件该成DrawColumnCell

procedure TfrmInput.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key<>chr(9)) then
begin
if (DBGrid1.SelectedField.FieldName=DBLookUPComboBox1.DataField) then
begin
DBLookupComboBox1.SetFocus;
SendMessage(DBLookupComboBox1.Handle,WM_Char, word(Key), 0);
end;
end;
end;


procedure TfrmInput.DBGrid1ColExit(Sender: TObject);
begin
if DBGrid1.SelectedField.FieldName== DBLookUpComboBox1.DataField then
DBLookupComboBox1.Visible := false;
end;


//****下面是与你不同的部分**********//
procedure TfrmInput.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if (gdFocused in State) and (Column.FieldName=DBLookUpcombobox1.Datafield) then
begin
//调整DBLookUpCombobox1的位置控制在Rect的范围内
DBLookupComboBox1.SetBounds(Rect.Left +DBGrid1.Left,
Rect.Top +DBGrid1.top,
Rect.Right-Rect.Left+2,
Rect.Bottom-Rect.Top-1
);
DBLookupComboBox1.Visible :=True;
end;

end;
tongki 2003-08-20
  • 打赏
  • 举报
回复
UP

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧