如何把StringGrid的列修改为可选择的CheckBox列呢?

本文介绍了如何在FreePascal的CodeTyphon环境中使用StringGrid组件,包括设置列宽、修改ButtonStyle属性将某些列转换为CheckBox或PickList,以及定制表头和单元格显示。还涉及了FixedRow的使用和Checkbox列的点击事件处理。
摘要由CSDN通过智能技术生成

本例操作在基于FreePascal的CodeTyphon上实现

一、表格列需要先在Columns属性中添加好
在这里插入图片描述
二、对要改为CheckBox的列进行ButtonStyle属性修改,选择为cbsCheckboxColumn,还可以为下拉列表框cbsPickList,选项在属性PickList项进行添加
在这里插入图片描述
三、Title标题Caption可以在下面的Title属性中设置,也可以在Show事件中设置
在这里插入图片描述

procedure TfrmPayway.FormShow(Sender: TObject);
begin
  with sgPayway do
  begin
      ColWidths[0]:=40;
      ColWidths[1]:=80;
      ColWidths[2]:=180;
      ColWidths[3]:=150;
      ColWidths[4]:=60;
      ColWidths[5]:=60;
      ColWidths[6]:=70;
      ColWidths[7]:=70;
      ColWidths[8]:=70;
      ColWidths[9]:=70;
      ColWidths[10]:=70;
      ColWidths[11]:=60;
      ColWidths[12]:=70;
      ColWidths[13]:=70;
    
      Cells[0,0]:='行号';
      Cells[1,0]:='支付代码';
      Cells[2,0]:='支付名称';
      Cells[3,0]:='入账账户';
      Cells[4,0]:='币种';
      Cells[5,0]:='汇率';
      Cells[6,0]:='营业收支';
      Cells[7,0]:='前台业务';
      Cells[8,0]:='后台业务';
      Cells[9,0]:='允许找零';
      Cells[10,0]:='允许超额';
      Cells[11,0]:='弹钱箱';
      Cells[12,0]:='虚拟收入';
      Cells[13,0]:='录入编号';
  end;
end; 

四、FixedRow不能为goFixedRowNumbering,会被DrawCell事件覆盖,可通过新增行或加载表格时直接赋值
在这里插入图片描述
在这里插入图片描述
五,同样也可以设置首列首行文本居中的

procedure TfrmPayway.sgPaywayDrawCell(Sender: TObject; aCol, aRow: Integer;
  aRect: TRect; aState: TGridDrawState);
var cellstr:String;
begin
  if (aRow = 0) OR (aCol=0) then
    begin
    cellstr:=sgPayway.Cells[aCol,aRow];
    sgPayway.Canvas.Clear;
      sgPayway.Canvas.TextRect(aRect,aRect.Left+(aRect.Right-aRect.Left-sgPayway.Canvas.TextWidth(cellstr)) div 2,
      aRect.Top+(aRect.Bottom-aRect.Top-sgPayway.Canvas.TextHeight(cellstr)) div 2,cellstr);
    end;
end;

六、StringGrid中的Checkbox列被点击后更新,在StringGrid的onMouseUP鼠标弹起事件中进行

procedure TfrmPayway.sgPayMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if not isadd then
  if sgPay.Col in[6..13] then ismod:=True;
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值