{ Options选项里面的goRowSelect设置为True时,一直有一个蓝色长条,比较难以实现编辑内容. 可以动态实现goRowSelect为真为假,当点击最左边的固定列时为真,否则为假. 在OnMouseDown中实现 } procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var SelectCol, SelectRow: Longint; SelectGrid: TGridRect; begin with StringGrid1 do begin MouseToCell(X, Y, SelectCol, SelectRow); if (SelectCol < FixedCols) and (SelectCol >= 0) then begin Options := Options + [goRowSelect]; with SelectGrid do begin Left := LeftCol; Top := SelectRow; Right := ColCount - 1; Bottom := SelectRow; Selection := SelectGrid; end; end else Options := Options - [goRowSelect]; end; end;
可以动态实现goRowSelect为真为假,当点击最左边的固定列时为真,否则为假.
在OnMouseDown中实现 }
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
SelectCol, SelectRow: Longint;
SelectGrid: TGridRect;
begin
with StringGrid1 do
begin
MouseToCell(X, Y, SelectCol, SelectRow);
if (SelectCol < FixedCols) and (SelectCol >= 0) then
begin
Options := Options + [goRowSelect];
with SelectGrid do
begin
Left := LeftCol;
Top := SelectRow;
Right := ColCount - 1;
Bottom := SelectRow;
Selection := SelectGrid;
end;
end
else
Options := Options - [goRowSelect];
end;
end;