AdvStringGrid1.Options:=[goEditing]; //设置单元格是否可编辑
AdvStringGrid1.MouseActions.DirectEdit:=True; //设置点击单元格即进入编辑状态
procedure TForm1.AdvStringGrid1CanEditCell(Sender: TObject; ARow, ACol: Integer; var CanEdit: Boolean);
var
i: Integer;
begin
for i := to AdvStringGrid1.ColCount do
begin
CanEdit := False;
end;
if ACol = then
CanEdit := True;
if ACol = then
CanEdit := True;
end;
//设置单元格对齐方式
procedure TForm1.AdvStringGrid1GetAlignment(Sender: TObject; ARow, ACol: Integer; var HAlign: TAlignment; var VAlign: TVAlignment);
begin
if ACol = then
begin
HAlign := taCenter; //TAlignment = (taLeftJustify, taRightJustify, taCenter);
VAlign := vtaCenter; //TVAlignment = (vtaTop,vtaCenter,vtaBottom);
end;
end;
//添加CheckBox
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
flag: Boolean;
begin
//添加CheckBox
for i := to AdvStringGrid1.RowCount - do
begin
AdvStringGrid1.AddCheckBox(, i, False, false);
end;
//判断CheckBox是否选中
for i := to AdvStringGrid1.RowCount - do
begin
AdvStringGrid1.GetCheckBoxState(, i, flag);
if flag then
begin
//如果选中CheckBox进行操作
end;
end;
end;
//AdvStringGrid1.Options:=[goEditing]; //设置单元格是否可编辑
//AdvStringGrid1.MouseActions.DirectEdit := True; //设置点击单元格即进入编辑状态
//为 AdvStringGrid1增加下拉列表选择框
procedure TForm1.AdvStringGrid1GetEditorType(Sender: TObject; ACol, ARow: Integer; var AEditor: TEditorType);
var
sqlStr: string;
begin
if ACol = then //设置特定列为下拉列表框类型
begin
sqlstr := 'select * from dictfeeitem';
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(sqlStr);
Open;
end;
if ADOQuery1.RecordCount > then
begin
ADOQuery1.First;
aEditor := edComboList; //设置编辑框为下拉列表
AdvStringGrid1.ClearComboString; //清空下拉列表内容
while not ADOQuery1.Eof do
begin
AdvStringGrid1.AddComboString(ADOQuery1.FieldByName('feeitem').AsString); //增加下拉列表框内容
ADOQuery1.Next;
end;
end;
end;
end;
//滚动条到最后一条记录
SendMessage(AdvStringGrid1.Handle,WM_VSCROLL,SB_BOTTOM,);
//根据内容改变单元格的颜色
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
AdvStringGrid1.RowCount := ;
AdvStringGrid1.Cells[, ] := '-11';
AdvStringGrid1.Cells[, ] := '';
AdvStringGrid1.Cells[, ] := '';
AdvStringGrid1.Cells[, ] := '-8';
AdvStringGrid1.Cells[, ] := '';
AdvStringGrid1.Cells[, ] := '';
for i := to AdvStringGrid1.RowCount - do
begin
if StrToInt(AdvStringGrid1.Cells[, i]) <= then
AdvStringGrid1.FontColors[, i] := clRed
else
AdvStringGrid1.FontColors[, i] := clBlack;
end;
end;