我用以下方法做成:
procedure TFormMain.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (column.Index =3) then
begin
ComboBox1.Left := Rect.Left + DBGrideh1.Left;
ComboBox1.Top := Rect.Top + DBGrideh1.top;
ComboBox1.Width := Rect.Right - Rect.Left;
ComboBox1.Height := Rect.Bottom - Rect.Top;
ComboBox1.Visible := True;
end;
end;
procedure TFormMain.DBGridEh1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> chr(9)) then
begin
if (DBGrideh1.SelectedField.FieldName='DateCode') then
begin
ComboBox1.SetFocus;
SendMessage(ComboBox1.Handle,WM_Char, word(Key), 0);
end;
end;
end;
procedure TFormMain.DBGridEh1ColExit(Sender: TObject);
begin
If DBGrideh1.SelectedField.FieldName='DateCode' then
begin
ComboBox1.Visible := false;
end;
end;
procedure TFormMain.ComboBox1DropDown(Sender: TObject);
begin
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select datecode from wstouliao where liaohao=:liaohao0 and riqi=:riqi0');
adoquery2.Parameters.ParamValues['liaohao0']:=adoquery1.FieldValues['liaohao'];
adoquery2.Parameters.ParamValues['riqi0']:=date();
adoquery2.Open;
adoquery2.First;
combobox1.Items.Clear;
while not adoquery2.Eof do
begin
combobox1.Items.Add(adoquery2.FieldValues['datecode']);
adoquery2.Next;
end;
end;
请问各位大侠:
1、以上做法可行吗?因为可能表中的数据记录量很大。
2、怎样将选取Combobox中的值放到DbGrideh中的栏位里去?