本例操作在基于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;