供参考:
var
a:TStringList;
begin
a:=TStringList.Create;
whdata.gg_spmc.Open;
while not whdata.gg_spmc.Eof do
begin
a.Add(whdata.gg_spmc.FieldValues['sp_name']);
whdata.gg_spmc.Next;
end;
dbgrid1.Columns[1].PickList:=a;
a.Free;
end;
picklist
或者
//DBGRID指定列显示DBCOMBOBOX的内容
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;
//DBGRID指定单元格未获得焦点时不显示DBCOMBOBOX
procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
begin
DBComboBox1.Visible := false;
end;
end;
//再DBCOMBOBOX上进行数据输入
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;
end;