参考:C:\lazarus\examples\gridexamples\gridcelleditor


procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl); begin if (aCol=3) and (aRow>0) then begin //哪些单元格 显示 ComboBox1 ComboBox1.BoundsRect:=StringGrid1.CellRect(aCol,aRow); ComboBox1.Text:=StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]; Editor:=ComboBox1; end; end;
ComboBox1选择完数据后,将选择结果返回给StringGrid1


procedure TForm1.ComboBox1EditingDone(Sender: TObject); begin StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=ComboBox1.Text; end;
其他编辑控件也类似,如DateTimePicker1
procedure TForm1.DateTimePicker1EditingDone(Sender: TObject); begin StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=datetostr( DateTimePicker1.Date); end;

C:\lazarus\examples\gridexamples\columneditors

然后设置每列的ButtonStyle


其中cbsPickList类型相当于 01]下拉ComboBox1选择


放一个ColorDialog1到界面上,并将其默认颜色为clWhite

将StringGrid1的某列ButtonStryle设为cbsButton

procedure TForm1.StringGrid1ButtonClick(Sender: TObject; aCol, aRow: integer); begin if (aCol = 8) and ColorDialog1.Execute then //Button begin //获得 Colordialog1.Color; StringGrid1.Repaint; end; end;

浙公网安备 33010602011771号