参考: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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-02-23 HTML竖条流程图,纯HTML,CSS 无JS
2022-02-23 Excel表格中自定义样式太多,删除办法: