procedure TForm1.StringGrid1DrawCell(Sender: TObject. ACol, ARow: Integer. Rect: TRect. State: TGridDrawState).
begin
with stringgrid1 do
begin
if cells[0,arow] = checked then
begin
canvas.brush.color := clhighlight;
canvas.font.color := clhighlighttext;
end
else
Canvas.Brush.Color := clWindow;
Canvas.Font.Color := clWindowText;
end
Canvas.FillRect(Rect);
TextRect(Rect, Rect.Left 2, Rect.Top 2, Cells[ACol, ARow]);
end;
end;
procedure 1.StringGrid1SelectCell(Sender: TObject. ACol, ARow: Integer. var CanSelect: Boolean);
begin
with 1 do
begin if ARow = Row then Exit;
if Cells[0, ARow] = Checked then
Cells[0, ARow] := UnChecked
else
Cells[0, ARow] := Checked
end;
end;
如何在TStringGrid控件中按ctrl键选择多行啊
推荐解答:
在MouseDown事件写入以下代码:
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ssCtrl in Shift then
StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goRowSelect]
else
StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRowSelect] ;
end;
delphi中StringGrid打开goRangeSelect可以多选,如何知道选择了那些Cell?
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
for i:=Stringgrid1.Selection.left to Stringgrid1.Selection.Right do
begin
for j:=Stringgrid1.Selection.Top to Stringgrid1.Selection.Bottom do
Stringgrid1.cells[i,j]:='ok';
end;
end;